From 2f65e831d8cede40306f1bd774e3345636b7c435 Mon Sep 17 00:00:00 2001 From: Jon Wright Date: Fri, 11 Sep 2020 09:07:45 -0400 Subject: [PATCH] fix: updates error handling to match axios --- src/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 2887773..61d4cd6 100644 --- a/src/index.js +++ b/src/index.js @@ -202,7 +202,6 @@ export default (function create(/** @type {Options} */ defaults) { } const ok = options.validateStatus ? options.validateStatus(res.status) : res.ok; - if (!ok) return Promise.reject(response); if (options.responseType == 'stream') { response.data = res.body; @@ -216,7 +215,7 @@ export default (function create(/** @type {Options} */ defaults) { response.data = JSON.parse(data); }) .catch(Object) - .then(() => response); + .then(() => (ok ? response : Promise.reject(response))); }); }