fix: add onResponse hook for response metadata inspection before streaming
This commit is contained in:
@@ -276,6 +276,11 @@ function streamCommandCode(
|
|||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
await raceAbort(Promise.resolve(options?.onResponse?.({
|
||||||
|
status: response.status,
|
||||||
|
headers: Object.fromEntries(response.headers.entries()),
|
||||||
|
}, model)));
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errBody = await raceAbort(response.text().catch(() => ""));
|
const errBody = await raceAbort(response.text().catch(() => ""));
|
||||||
throw new Error(`Command Code API error ${response.status}: ${errBody.slice(0, 500)}`);
|
throw new Error(`Command Code API error ${response.status}: ${errBody.slice(0, 500)}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user