Skip to content
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

New throwIfResponseIsError hook #115

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Dec 9, 2022

We previously removed didReceiveResponse which let you override the main "is it an error or not" logic. This restores it in an error-specific way. This means you can throw errors even on 200s if you want (or vice versa).

This also changes the errorFromResponse hook to take options instead of a single argument, in case you want the error to reflect more data.

One negative change is you can no longer prevent parseBody from being called, though you can always override parseBody to do less.

Fixes #32.

We previously removed `didReceiveResponse` which let you override the
main "is it an error or not" logic. This restores it in an
error-specific way. This means you can throw errors even on 200s if you
want (or vice versa).

This also changes the `errorFromResponse` hook to take options instead
of a single argument, in case you want the error to reflect more data.

One negative change is you can no longer prevent `parseBody` from being
called, though you can always override `parseBody` to do less.

Fixes #32.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 9, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@glasser
Copy link
Member Author

glasser commented Dec 9, 2022

This does conflict a bit with #110, sorry.

I didn't update README because the original hook wasn't documented. At some point I think you do need to assume that people who want to customize by overriding protected methods will just read the source...

@glasser glasser merged commit be4371f into main Dec 9, 2022
@glasser glasser deleted the glasser/control-when-error-is-thrown branch December 9, 2022 20:07
@github-actions github-actions bot mentioned this pull request Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RESTDataSource, cannot easily throw error if response is 200
2 participants