makes it easier for clients to detect proxy errors programatically
This commit is contained in:
parent
9d00b8a9de
commit
57fd17ede0
|
@ -52,7 +52,13 @@ function getMessageContent({
|
|||
delete obj.stack;
|
||||
}
|
||||
|
||||
return [header, friendlyMessage, serializedObj, prettyTrace].join("\n\n");
|
||||
return [
|
||||
header,
|
||||
friendlyMessage,
|
||||
serializedObj,
|
||||
prettyTrace,
|
||||
"<!-- oai-proxy-error -->",
|
||||
].join("\n\n");
|
||||
}
|
||||
|
||||
type ErrorGeneratorOptions = {
|
||||
|
@ -116,6 +122,11 @@ export function sendErrorToClient({
|
|||
const isStreaming =
|
||||
req.isStreaming || req.body.stream === true || req.body.stream === "true";
|
||||
|
||||
if (!res.headersSent) {
|
||||
res.setHeader("x-oai-proxy-error", options.title);
|
||||
res.setHeader("x-oai-proxy-error-status", options.statusCode || 500);
|
||||
}
|
||||
|
||||
if (isStreaming) {
|
||||
if (!res.headersSent) {
|
||||
initializeSseStream(res);
|
||||
|
|
Loading…
Reference in New Issue