OpenAI integration: retry 400 status code because OpenAI returns this sometimes for no reason (#898)

This commit is contained in:
Matt Aitken
2024-02-12 12:48:48 +00:00
committed by GitHub
parent 7fae67c47d
commit d69e4e712d
2 changed files with 34 additions and 27 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/openai": patch
---
Retry 400 status code, OpenAI returns this sometimes for no reason...
+3 -1
View File
@@ -128,6 +128,8 @@ export function handleOpenAIError(error: unknown) {
} }
return ( return (
//sometimes OpenAI returns a 400 that when retried becomes a 200…
error.status === 400 ||
error.status === 429 || error.status === 429 ||
error.status === 408 || error.status === 408 ||
error.status === 409 || error.status === 409 ||
@@ -295,7 +297,7 @@ const requestOptionsKeys: KeysEnum<OpenAIRequestOptions> = {
export const isRequestOptions = (obj: unknown): obj is OpenAIRequestOptions => { export const isRequestOptions = (obj: unknown): obj is OpenAIRequestOptions => {
return ( return (
typeof obj === 'object' && typeof obj === "object" &&
obj !== null && obj !== null &&
!isEmptyObj(obj) && !isEmptyObj(obj) &&
Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k)) Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k))