Skip to content

Commit 7f2aa62

Browse files
committed
fix(client-ofetch): keep error responses from throwing
1 parent 26c1638 commit 7f2aa62

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export interface Config<T extends ClientOptions = ClientOptions>
3939
* @default globalThis.fetch
4040
*/
4141
fetch?: typeof fetch;
42+
/**
43+
* Controls the native ofetch behaviour that throws `FetchError` when
44+
* `response.ok === false`. We default to suppressing it to match the fetch
45+
* client semantics and let `throwOnError` drive the outcome.
46+
*/
47+
ignoreResponseError?: OfetchOptions['ignoreResponseError'];
4248
// No custom fetch option: provide custom instance via `ofetch` instead
4349
/**
4450
* Please don't use the Fetch client for Next.js applications. The `next`

packages/openapi-ts/src/plugins/@hey-api/client-ofetch/bundle/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ export const buildOfetchOptions = (
322322
body,
323323
dispatcher: opts.dispatcher as OfetchOptions['dispatcher'],
324324
headers: opts.headers as Headers,
325+
ignoreResponseError:
326+
(opts.ignoreResponseError as OfetchOptions['ignoreResponseError']) ??
327+
true,
325328
method: opts.method,
326329
onRequest: opts.onRequest as OfetchOptions['onRequest'],
327330
onRequestError: opts.onRequestError as OfetchOptions['onRequestError'],
@@ -530,6 +533,7 @@ export const createConfig = <T extends ClientOptions = ClientOptions>(
530533
): Config<Omit<ClientOptions, keyof T> & T> => ({
531534
...jsonBodySerializer,
532535
headers: defaultHeaders,
536+
ignoreResponseError: true,
533537
parseAs: 'auto',
534538
querySerializer: defaultQuerySerializer,
535539
...override,

0 commit comments

Comments
 (0)