fixes server blowing up when a streaming request drops out

This commit is contained in:
nai-degen 2023-05-04 16:37:16 -05:00
parent be1e672e68
commit 4dc9c649d8
1 changed files with 20 additions and 16 deletions

View File

@ -294,14 +294,15 @@ const handleDownstreamErrors: ProxyResHandlerWithBody = async (
throw new Error(errorPayload.error?.message);
};
/** Handles errors in the request rewriter pipeline. */
/** Handles errors in rewriter pipelines. */
export const handleInternalError: httpProxy.ErrorCallback = (
err,
_req,
res
) => {
logger.error({ error: err }, "Error in proxy request pipeline.");
logger.error({ error: err }, "Error in http-proxy-middleware pipeline.");
// headers might have already been sent
try {
(res as http.ServerResponse).writeHead(500, {
"Content-Type": "application/json",
});
@ -315,6 +316,9 @@ export const handleInternalError: httpProxy.ErrorCallback = (
},
})
);
} catch (e) {
logger.error({ error: e }, "Error writing error response headers, giving up.");
}
};
const incrementKeyUsage: ProxyResHandlerWithBody = async (_proxyRes, req) => {