Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
fix(api-utils): simplified json parsing for request
Browse files Browse the repository at this point in the history
fix(api-utils): simplified json parsing for request
  • Loading branch information
Metnew committed Feb 19, 2018
1 parent ba143a6 commit b88f800
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/common/api/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b88f800

Please sign in to comment.