Skip to content
Source
Sign inSign up
TanStack/schemas

Retry the OpenAI models listing on a transient 504 #687

Mergedtombeckenhammerged 1 commit intomain from100004-openai-one-upstream-504-on-get-v1-models-fails-the-whole-modmerged by tombeckenham View on GitHub

Showing 2 changed files with 62 additions and 5 deletions.

x
0 of 2 viewed, 2 left
55 additions and 1 deletionsrc/server/providers/openai.test.tsModified
View file
@@ -1,4 +1,4 @@
-import { expect, it } from 'vitest'
+import { expect, it, vi } from 'vitest'
import {
OPENAI_GPT51_GUIDE_URL,
OPENAI_GPT52_GUIDE_URL,
@@ -60,3 +60,57 @@
globalThis.fetch = original
})
+​
+/** Listing answers from `responses` in order; docs loads get an empty page. */
+async function listWithListing(responses: Array<() => Response>) {
+ const original = globalThis.fetch
+ const auth: Array<string | null> = []
+ globalThis.fetch = ((url: string, init?: RequestInit) => {
+ if (String(url).includes('developers.openai.com'))
+ return Promise.resolve(new Response('# Docs'))
+ auth.push(new Headers(init?.headers).get('authorization'))
+ const next = responses[auth.length - 1]
+ if (!next) throw new Error('listing called more often than stubbed')
+ return Promise.resolve(next())
+ }) as typeof fetch
+ vi.useFakeTimers()
+ try {
+ const settled = openaiProvider