makes it easier for clients to detect proxy errors programatically

This commit is contained in:
nai-degen 2024-05-27 15:30:28 -05:00
parent 9d00b8a9de
commit 57fd17ede0
1 changed files with 12 additions and 1 deletions

View File

@ -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);