1
0
mirror of https://github.com/ascribe/onion.git synced 2025-02-14 21:10:27 +01:00

Only assume TypeError if request's response is null

This commit is contained in:
Brett Sun 2015-12-14 14:54:57 +01:00
parent e24c9c9c74
commit d9615188b0

View File

@ -10,7 +10,12 @@ import { argsToQueryParams } from '../utils/url_utils';
class Requests {
unpackResponse(response) {
unpackResponse(url) {
return (response) => {
if (response == null) {
throw new Error('For: ' + url + ' - Server did not respond to the request. (Not even displayed a 500)');
}
if (response.status >= 500) {
let err = new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url);
@ -66,15 +71,6 @@ class Requests {
}).catch(reject);
});
}
handleError(url) {
return (err) => {
if (err instanceof TypeError) {
throw new Error('For: ' + url + ' - Server did not respond to the request. (Not even displayed a 500)');
} else {
throw err;
}
};
}
getUrl(url) {
@ -128,8 +124,7 @@ class Requests {
}
merged.method = verb;
return fetch(url, merged)
.then(this.unpackResponse)
.catch(this.handleError(url));
.then(this.unpackResponse(url));
}
get(url, params) {