mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Only assume TypeError if request's response is null
This commit is contained in:
parent
e24c9c9c74
commit
d9615188b0
@ -10,7 +10,12 @@ import { argsToQueryParams } from '../utils/url_utils';
|
|||||||
|
|
||||||
|
|
||||||
class Requests {
|
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) {
|
if (response.status >= 500) {
|
||||||
let err = new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url);
|
let err = new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url);
|
||||||
|
|
||||||
@ -66,15 +71,6 @@ class Requests {
|
|||||||
}).catch(reject);
|
}).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) {
|
getUrl(url) {
|
||||||
@ -128,8 +124,7 @@ class Requests {
|
|||||||
}
|
}
|
||||||
merged.method = verb;
|
merged.method = verb;
|
||||||
return fetch(url, merged)
|
return fetch(url, merged)
|
||||||
.then(this.unpackResponse)
|
.then(this.unpackResponse(url));
|
||||||
.catch(this.handleError(url));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url, params) {
|
get(url, params) {
|
||||||
|
Loading…
Reference in New Issue
Block a user