Skip to content

Commit 7f67c89

Browse files
committed
feat: Forward headers from error responses in chat completions route
1 parent adac0e2 commit 7f67c89

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/routes/chat-completions/route.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ function handleFetchError(
5151
c: Context<BlankEnv, "/", BlankInput>,
5252
error: FetchError,
5353
) {
54+
const status = error.response?.status ?? 500
55+
56+
// Forward all headers from the error response
57+
error.response?.headers.forEach((value, key) => {
58+
c.header(key, value)
59+
})
60+
5461
return c.json(
5562
{
5663
error: {
@@ -59,7 +66,7 @@ function handleFetchError(
5966
data: error.response?._data as unknown,
6067
},
6168
},
62-
(error.response?.status ?? 500) as ContentfulStatusCode,
69+
status as ContentfulStatusCode,
6370
)
6471
}
6572

@@ -72,6 +79,11 @@ async function handleResponseError(
7279
`Request failed: ${error.status} ${error.statusText}: ${errorText}`,
7380
)
7481

82+
// Forward all headers from the error response
83+
error.headers.forEach((value, key) => {
84+
c.header(key, value)
85+
})
86+
7587
return c.json(
7688
{
7789
error: {

0 commit comments

Comments
 (0)