Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork552
feat: Attach fetch response to SWR data/error#2246
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 ourterms of service andprivacy 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?
Conversation
It is useful to have the original fetch response available in the hook result. For instance to distinguish the HTTP status code in case of an `error`.Since SWR only returns `error` / `data` properties, this provides an escape hatch to be able to access to original `fetch` response, as returned by the `openapi-fetch` client.
netlifybot commentedApr 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
👷 Deploy request foropenapi-ts pending review.Visit the deploys page to approve it
|
changeset-botbot commentedApr 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
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.
Thanks! Not opposed to this fix itself, but we will need a test to make sure this doesn’t regress in the future.
Could you describe the error you were seeing when running the test suite? Are you on the current LTS Node version (22) and did you follow the instructions inCONTRIBUTING.md
?
Uh oh!
There was an error while loading.Please reload this page.
Changes
It is useful to have the original fetch response available in the hook result. For instance to distinguish the HTTP status code in case of an
error
. Since SWR only returnserror
/data
properties, this provides an escape hatch to be able to access to originalfetch
response, as returned by theopenapi-fetch
client.This will probably fail for JSON bodies that parse to primitives (null/string).
#2238
Checklist
I was unable to run the test suite, making it hard to add / update unit tests for me.