Skip to content

Commit 0655825

Browse files
committed
fix(providers): let a deadline while reading an error body propagate
1 parent d0dce45 commit 0655825

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

apps/sim/providers/openai/core.transport-phase.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,25 @@ describe('OpenAI transport phase annotation', () => {
174174
expect(fetchMock).toHaveBeenCalledTimes(2)
175175
})
176176

177+
/**
178+
* Reading the error body of a non-OK response can itself hit the deadline or be
179+
* cancelled. Swallowing that would report the HTTP status as the failure and lose both
180+
* the transport detail and the fact that the user aborted.
181+
*/
182+
it('propagates a deadline hit while reading a non-OK error body', async () => {
183+
const unreadable = {
184+
ok: false,
185+
status: 502,
186+
headers: new Headers(),
187+
text: () => Promise.reject(timeoutError()),
188+
}
189+
190+
const error = await run(vi.fn().mockResolvedValue(unreadable)).catch((e) => e)
191+
192+
expect(error.message).toContain('The operation timed out.')
193+
expect(error.message).not.toContain('502')
194+
})
195+
177196
it('leaves a healthy response entirely unaffected', async () => {
178197
const fetchMock = vi.fn().mockResolvedValue({
179198
ok: true,

apps/sim/providers/openai/core.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,12 @@ export async function executeResponsesProviderRequest(
292292
* block error, so it is bounded and falls back to `statusText`. A structured provider
293293
* message is returned untruncated on purpose: the reasoning-summary strip-and-retry
294294
* fallback matches on its text.
295+
*
296+
* A failed body read is deliberately not caught: a deadline or a cancellation here must
297+
* stay distinguishable from an error response that simply carried no body.
295298
*/
296299
const parseErrorResponse = async (response: Response): Promise<string> => {
297-
const text = await response.text().catch(() => '')
300+
const text = await response.text()
298301
try {
299302
const payload = JSON.parse(text)
300303
if (payload?.error?.message) return payload.error.message

0 commit comments

Comments
 (0)