FACG6 / posts-project

https://postproject1.herokuapp.com/
0 stars 0 forks source link

Handling errors in fetch #23

Open FarahZaqout opened 5 years ago

FarahZaqout commented 5 years ago

https://github.com/FACG6/posts-project/blob/543acb90ac266203e938b072a03ac282f6506b41/public/js/domSignup.js#L176

The .catch() method in your fetch will not be able to handle a 4xx or 5xx response from the server.

This is handled in the .then() method.

.then((res) => {
   if (res.status === 500) // handle server error here
   if (res.status === 400) // handle bad request error here
})

the catch in fetch will only see a network error.

NouraldinS commented 5 years ago

@FarahZaqout I knew that I'd be curious to a few things while reading your issues :p, that's why I am reading them. A. you can select multiple lines and reference them in the issue while holding the shift key and selecting the lines from the repo :p B. I might not disagree with what you're stating here, someone else might :p https://softwareengineering.stackexchange.com/questions/350498/handling-errors-in-a-client-server-application

FarahZaqout commented 5 years ago

@NoureldeanSaed Yeah, I agree with the post. That's why I'm only checking for status code, a message is unnecessary in these sorts of situations and he can end the response with no worries.