diff --git a/src/providers/claude.ts b/src/providers/claude.ts index 495110f..f768955 100644 --- a/src/providers/claude.ts +++ b/src/providers/claude.ts @@ -69,6 +69,14 @@ const sendRequestFunc = (settings: ClaudeOptions): SendRequest => agent: proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined }) + if (!response || !response.body) { + throw new Error('No response') + } + if (!response.ok) { + console.error('response', response) + throw new Error(`Unexpected response status: ${response.status} ${response.statusText}`) + } + // @ts-ignore const stream = Stream.fromSSEResponse(response, new AbortController()) diff --git a/src/providers/doubao.ts b/src/providers/doubao.ts index 7023cb3..0a8dce5 100644 --- a/src/providers/doubao.ts +++ b/src/providers/doubao.ts @@ -28,6 +28,10 @@ const sendRequestFunc = (settings: BaseOptions): SendRequest => if (!response || !response.body) { throw new Error('No response') } + if (!response.ok) { + console.error('response', response) + throw new Error(`Unexpected response status: ${response.status} ${response.statusText}`) + } const decoder = new TextDecoder('utf-8') for await (const chunk of response.body) { const lines = decoder.decode(Buffer.from(chunk)) diff --git a/src/providers/qianFan.ts b/src/providers/qianFan.ts index abf2eca..926dbbb 100644 --- a/src/providers/qianFan.ts +++ b/src/providers/qianFan.ts @@ -107,6 +107,11 @@ const sendRequestFunc = (settings: QianFanOptions): SendRequest => if (!response || !response.body) { throw new Error('No response') } + if (!response.ok) { + console.error('response', response) + throw new Error(`Unexpected response status: ${response.status} ${response.statusText}`) + } + const buffer: string[] = [] const decoder = new TextDecoder('utf-8') for await (const chunk of response.body) {