mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
Fix Request error case
This commit is contained in:
parent
3e8e7a40e7
commit
7605f093ab
@ -13,11 +13,17 @@ class Requests {
|
|||||||
unpackResponse(response) {
|
unpackResponse(response) {
|
||||||
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);
|
||||||
response
|
|
||||||
|
return response
|
||||||
.text()
|
.text()
|
||||||
.then((resText) => JSON.parse(resText))
|
.then((resText) => {
|
||||||
.then((resJSON) => {
|
const resJson = JSON.parse(resText);
|
||||||
err = new Error(resJSON.errors.pop());
|
err = new Error(resJson.errors.pop());
|
||||||
|
|
||||||
|
// ES6 promises don't have a .finally() clause so
|
||||||
|
// we fake that here by forcing the .catch() clause
|
||||||
|
// to run
|
||||||
|
return Promise.reject();
|
||||||
})
|
})
|
||||||
.catch(() => { throw err; });
|
.catch(() => { throw err; });
|
||||||
}
|
}
|
||||||
@ -57,9 +63,7 @@ class Requests {
|
|||||||
resolve({});
|
resolve({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch(reject);
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user