feat: Attach fetch response to SWR data/error#2246
feat: Attach fetch response to SWR data/error#2246Tommos0 wants to merge 2 commits intoopenapi-ts:mainfrom
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.
👷 Deploy request for openapi-ts accepted.
|
|
drwpow
left a comment
There was a problem hiding this comment.
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 in CONTRIBUTING.md?
|
Just a heads up: the repo has since been moved here, so this PR will need to be moved to changeset-release/main. Please feel free to repoen there! (But the test requirements will be the same) |
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/dataproperties, this provides an escape hatch to be able to access to originalfetchresponse, as returned by theopenapi-fetchclient.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.