1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01: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) { 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);
});
}); });
} }