-
-
Notifications
You must be signed in to change notification settings - Fork 373
fix(client-ofetch): set ignoreResponseError default to false and handle FetchError response #3856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,7 +180,19 @@ export const createClient = (config: Config = {}): Client => { | |
| // build ofetch options and perform the request (.raw keeps the Response) | ||
| const responseOptions = buildNetworkOptions(opts, networkBody, ofetchResponseType); | ||
|
|
||
| response = await $ofetch.raw(finalUrl, responseOptions); | ||
| try { | ||
| response = await $ofetch.raw(finalUrl, responseOptions); | ||
| } catch (fetchError: unknown) { | ||
| // When ignoreResponseError is false (default), ofetch throws FetchError for non-2xx. | ||
| // Extract the response so response interceptors can still process it before we | ||
| // decide whether to throw or return the error. | ||
| const maybeFetchError = fetchError as { response?: typeof response }; | ||
| if (maybeFetchError?.response) { | ||
| response = maybeFetchError.response; | ||
| } else { | ||
| throw fetchError; | ||
| } | ||
| } | ||
|
Comment on lines
+183
to
+195
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking, but worth noting: real |
||
|
|
||
| for (const fn of interceptors.response.fns) { | ||
| if (fn) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -299,7 +299,8 @@ export const buildOfetchOptions = ( | |
| credentials: opts.credentials as OfetchOptions['credentials'], | ||
| dispatcher: opts.dispatcher as OfetchOptions['dispatcher'], | ||
| headers: opts.headers as Headers, | ||
| ignoreResponseError: (opts.ignoreResponseError as OfetchOptions['ignoreResponseError']) ?? true, | ||
| ignoreResponseError: | ||
| (opts.ignoreResponseError as OfetchOptions['ignoreResponseError']) ?? false, | ||
| method: opts.method, | ||
| onRequest: opts.onRequest as OfetchOptions['onRequest'], | ||
| onRequestError: opts.onRequestError as OfetchOptions['onRequestError'], | ||
|
|
@@ -499,7 +500,7 @@ export const createConfig = <T extends ClientOptions = ClientOptions>( | |
| ): Config<Omit<ClientOptions, keyof T> & T> => ({ | ||
| ...jsonBodySerializer, | ||
| headers: defaultHeaders, | ||
| ignoreResponseError: true, | ||
| ignoreResponseError: false, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The central behavioral change of this PR is the flip from |
||
| parseAs: 'auto', | ||
| querySerializer: defaultQuerySerializer, | ||
| ...override, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no test asserting the opt-out path (
ignoreResponseError: true) still works as a backward-compat escape hatch. A future change forcing the option tofalseregardless of user input would go unnoticed. Consider a fourth test that passesignoreResponseError: true, usesmockResolvedValue(response404)(not rejected), and asserts the client returns{ error, response }without entering the new catch branch.