We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c804468 commit 955c781Copy full SHA for 955c781
2 files changed
src/lib/copilot-fetch.ts
@@ -73,6 +73,7 @@ function shouldRetryResponse(response: Response, bodyLength: number): boolean {
73
|| response.status === 409
74
|| response.status === 425
75
|| response.status === 429
76
+ || response.status === 499
77
|| response.status === 500
78
|| response.status === 502
79
|| response.status === 503
tests/create-chat-completions.test.ts
@@ -54,3 +54,24 @@ test("sets X-Initiator to user if only user present", async () => {
54
).headers
55
expect(headers["X-Initiator"]).toBe("user")
56
})
57
+
58
+test("retries transient upstream 499 responses", async () => {
59
+ const fetchMock = mock(() => {
60
+ if (fetchMock.mock.calls.length === 1) {
61
+ return new Response(null, { status: 499, statusText: "status code 499" })
62
+ }
63
+ return new Response(
64
+ JSON.stringify({ id: "123", object: "chat.completion", choices: [] }),
65
+ { status: 200, headers: { "content-type": "application/json" } },
66
+ )
67
+ })
68
+ globalThis.fetch = fetchMock as unknown as typeof fetch
69
70
+ const response = await createChatCompletions({
71
+ messages: [{ role: "user", content: "hi" }],
72
+ model: "gpt-test",
+ expect(response).toMatchObject({ id: "123" })
+ expect(fetchMock).toHaveBeenCalledTimes(2)
+})
0 commit comments