fix(llms): handle AbortError during .json()
This commit is contained in:
@@ -79,9 +79,13 @@ export class OpenAIClient implements LLMClient {
|
|||||||
|
|
||||||
// 3. Handle HTTP errors
|
// 3. Handle HTTP errors
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json().catch()
|
let errorData: any
|
||||||
const errorMessage =
|
try {
|
||||||
(errorData as { error?: { message?: string } }).error?.message || response.statusText
|
errorData = await response.json()
|
||||||
|
} catch (error) {
|
||||||
|
if ((error as any)?.name === 'AbortError') throw error
|
||||||
|
}
|
||||||
|
const errorMessage = errorData?.error?.message || response.statusText
|
||||||
|
|
||||||
if (response.status === 401 || response.status === 403) {
|
if (response.status === 401 || response.status === 403) {
|
||||||
throw new InvokeError(
|
throw new InvokeError(
|
||||||
@@ -116,6 +120,7 @@ export class OpenAIClient implements LLMClient {
|
|||||||
try {
|
try {
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if ((error as any)?.name === 'AbortError') throw error
|
||||||
throw new InvokeError(
|
throw new InvokeError(
|
||||||
InvokeErrorTypes.INVALID_RESPONSE,
|
InvokeErrorTypes.INVALID_RESPONSE,
|
||||||
'Response body is not valid JSON',
|
'Response body is not valid JSON',
|
||||||
|
|||||||
Reference in New Issue
Block a user