From b88f80016b417feddae418b67899c158b2e36e42 Mon Sep 17 00:00:00 2001 From: Vladimir Metnev Date: Mon, 19 Feb 2018 02:42:48 +0200 Subject: [PATCH] fix(api-utils): simplified json parsing for request fix(api-utils): simplified json parsing for request --- src/common/api/utils/index.js | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/common/api/utils/index.js b/src/common/api/utils/index.js index 589d2e83..bdbdedee 100644 --- a/src/common/api/utils/index.js +++ b/src/common/api/utils/index.js @@ -31,21 +31,9 @@ function requestWrapper (method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH') { } async function parseJSON (res: Response): Object { - let json: Object - // response status field - const {status} = res - try { - json = await res.json() - } catch (e) { - if (res.status === 204) { - return {ok: true, data: {}, status} - } - return {ok: false, status} - } - if (!res.ok) { - return {data: json, ok: false, status} - } - return {data: json, ok: true, status} + const data = await res.json() + const {status, ok} = res + return {data, ok, status} } // Could save you some time: // function checkStatus (response: Response): Response {