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

Should not reject on 400+ responses #6

Closed
Ethan-Arrowood opened this issue Jan 30, 2019 · 3 comments
Closed

Should not reject on 400+ responses #6

Ethan-Arrowood opened this issue Jan 30, 2019 · 3 comments

Comments

@Ethan-Arrowood
Copy link

Great work on this module. One recommendation is that you should not reject on 400+ responses. From discussions throughout other like projects (whatwg/fetch#18) I believe its a common practice to allow the user to decide what happens with their response. The promise should only reject if an actual network error occurs.

Now, this is your library and 100% your opinion so I'm not telling you to change anything; just sharing information you may not have been exposed to.

Good work nonetheless!

@lukeed
Copy link
Owner

lukeed commented Jan 30, 2019

Hey, thank you 🙌

The earliest versions of this didn't reject on 400+. I used it for a bit and tbh I didn't like it. It made testing easy, but I/you inevitably end up adding if blocks or switch statements to react to the status code.

This was far more verbose & annoying in the long run IMO.

I decided to roll with 400+ rejections to follow the HTTP status codea' meaning more closely. Anything above 400 is a non-successful response, which, in userland, translates to an abruption in your "happy path" 99% of the time.

That, to me, almost exactly describes a catch 😄

Sounds reasonable?

@Ethan-Arrowood
Copy link
Author

Yes very true. I used to have this exact thought pattern, but when I started working with the fetch api I needed to rewire my thinking to the other way. As long as you have this well documented (which you do) then I think you're good to go 😁

@lukeed
Copy link
Owner

lukeed commented Jan 30, 2019

Awesome, thank you 🙇

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

No branches or pull requests

2 participants