Skip to content

Commit 52b7627

Browse files
committed
Handle API error responses when streaming
1 parent c5d67b5 commit 52b7627

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/core/src/v3/apiClient/runStream.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
IOPacket,
99
parsePacket,
1010
} from "../utils/ioSerialization.js";
11+
import { ApiError } from "./errors.js";
1112
import { ApiClient } from "./index.js";
1213
import { AsyncIterableStream, createAsyncIterableStream, zodShapeStream } from "./stream.js";
1314
import { EventSourceParserStream } from "eventsource-parser/stream";
@@ -119,6 +120,15 @@ export class SSEStreamSubscription implements StreamSubscription {
119120
},
120121
signal: this.options.signal,
121122
}).then((response) => {
123+
if (!response.ok) {
124+
throw ApiError.generate(
125+
response.status,
126+
{},
127+
"Could not subscribe to stream",
128+
Object.fromEntries(response.headers)
129+
);
130+
}
131+
122132
if (!response.body) {
123133
throw new Error("No response body");
124134
}

0 commit comments

Comments
 (0)