Closed Exsilium122 closed 8 years ago
Sorry, master was not completely uptodate.
What I'm currently doing in version 0.12.8 is:
if (response.status >= 200 && response.status < 400) {
return response.json().catch(error => null);
}
throw response;
Does that feels ok for you?
Is there any reason why in case of erroneous response code you reject promise with new
Error
object? I found it problematic since in user code there is no way to find out what went wrong. Having response it is possible to read body or status code and decide what should be displayed or fixed.I understand that you pass
statusText
from the response, but this is not enough information. Look at your sample application. In sign up you sent 409 code if email is already in database. What if you have also password strength validation then you should sent different status code (400 I guess). Then those are two different reasons of failure.Also compatibility problem arise. according to https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/statusText statusText is a standard (still not much information in it), however when it comes to fetch: https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText it is not impemented in IE and Safari. Yeah probably fetch polyfill can fix it, but still not much information in it.