1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-26 11:16:28 +02:00

Fix Request error case

This commit is contained in:
Brett Sun 2015-12-09 14:44:31 +01:00
parent 3e8e7a40e7
commit 7605f093ab

View File

@ -13,11 +13,17 @@ class Requests {
unpackResponse(response) {
if (response.status >= 500) {
let err = new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url);
response
return response
.text()
.then((resText) => JSON.parse(resText))
.then((resJSON) => {
err = new Error(resJSON.errors.pop());
.then((resText) => {
const resJson = JSON.parse(resText);
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; });
}
@ -57,9 +63,7 @@ class Requests {
resolve({});
}
}
}).catch((err) => {
reject(err);
});
}).catch(reject);
});
}