feat(openapi-fetch): add onError handler to middleware#1974
feat(openapi-fetch): add onError handler to middleware#1974drwpow merged 1 commit intoopenapi-ts:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 4e32f31 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
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.
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
patchchangeset withnpx changesetin 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
Thanks so much! This all looks great. But yes this should be a Once this has a |
|
Is it really necessary to reinvent try...catch? Why |
1e2bfae to
38e6ed5
Compare
38e6ed5 to
4e32f31
Compare
I amended the commit with a |
|
@zsugabubus I’m not sure what you’re asking. If you have a feature request or bug to report, please open an issue using the appropriate template |
Changes
This PR adds an optional
onErrorhandler to the middleware feature. It allows handling errors thrown byfetchin three ways:Errorto be thrown instead,Responsewhich means that thefetchcall will proceed as successful.How to Review
See additional tests in
packages/openapi-fetch/test/middleware/middleware.test.tsIf multiple middlewares with
onErrorare 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:examplesrun (only applicable for openapi-typescript)