-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add an option to allow http errors #207
Comments
This looks like a step in the right direction, but it still doesn't feel friendly to communicate with real REST APIs. I may be missing something obvious (new to Nuxt/$fetch/ofetch), but even with the PR, I don't see a way to get the HTTP status code unless it's explicitly returned by the API as a JSON field, or unless I hook into the interceptors ( |
If you need the status codes, use native fetch or For non-errors: For errors: import { FetchError, ofetch } from "ofetch";
try {
await ofetch(...)
} catch(e) {
if(e instanceof FetchError) {
console.log(e.statusCode);
}
} |
* feat: support ignoreResponseError option #207 * lint * add ignore check to the wrapper * update readme --------- Co-authored-by: Pooya Parsa <[email protected]>
ofetch by default throws an error if the response status code is any of http standard error codes (such as 50x). However there are situations that users prefer to always get it as a response.
Currently, we provide a solution in docs (https://github.com/unjs/ofetch#%EF%B8%8F-handling-errors), to use
.error(err => err.data)
. However in wrapped contexts when user is not directly using$fetch
context, it is impossible. (nuxt/nuxt#18713).A new option like
ignoreResponseError
would make it possible to opt-out from the feature.The text was updated successfully, but these errors were encountered: