-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
feat(openapi-fetch): add onError handler to middleware #1974
base: main
Are you sure you want to change the base?
Conversation
|
Before middleware was added to I could of course keep my fetch wrapper for handling failed requests, but that would spread the logging logic across two places. |
b5a475e
to
61e7b76
Compare
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.
I really like this, thank you! I agree with your implementation of not throwing an error on any non-OK response, but just handling the instances where fetch()
itself throws.
Tests look great, too!
Only things we need to merge this PR:
- Update the documentation to mention this method (since docs update on merge). You don’t have to write much; just anything that mentions it exists, basically.
- Add a
patch
changeset withnpx changeset
in the root (in 0.x, we’re using minor versions to indicate breaking changes, and this is not a breaking change)
0fb2e2f
to
72dbb8a
Compare
I updated the docs. Feel free to make suggestions if something is missing or could be explained better somehow (or weird phrasing as I'm not a native speaker 😄). Just to be sure: since this is a new feature, shouldn't it be a |
72dbb8a
to
1e2bfae
Compare
Changes
This PR adds an optional
onError
handler to the middleware feature. It allows handling errors thrown byfetch
in three ways:Error
to be thrown instead,Response
which means that thefetch
call will proceed as successful.How to Review
See additional tests in
packages/openapi-fetch/test/middleware/middleware.test.ts
If multiple middlewares with
onError
are configured, they are executed in reverse order likeonResponse
. I'm not sure if that's intuitive or not. 🤔Checklist
docs/
updated (if necessary) 👈 I'll amend the commit with docs if this feature request is acceptedpnpm run update:examples
run (only applicable for openapi-typescript)