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

Commit

Permalink
fix(api): commented checkStatus func
Browse files Browse the repository at this point in the history
fix(api): commented checkStatus func
  • Loading branch information
Metnew committed Feb 18, 2018
1 parent bad63f8 commit dd3110b
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/common/api/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fetch from 'isomorphic-fetch'

// USAGE:
export const get = requestWrapper('GET')
// get('https://www.google.com', options)
// get('https://www.google.com')
export const post = requestWrapper('POST')
// post('https://www.google.com', data)

Expand All @@ -24,16 +24,16 @@ function requestWrapper (method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH') {
}

return fetch(url, request)
.then(checkStatus)
// .then(checkStatus)
.then(parseJSON)
.catch((err: any) => err)
}
}

async function parseJSON (res: Response): Object {
let json: Object
// response status field
const {status} = res
// status response field in return object
try {
json = await res.json()
} catch (e) {
Expand All @@ -47,26 +47,26 @@ async function parseJSON (res: Response): Object {
}
return {data: json, ok: true, status}
}

function checkStatus (response: Response): Response {
const {status} = response
if (status >= 200 && status < 300) {
// Everything is ok
} else if (status >= 300 && status < 400) {
// 300 - Multiple Choices
// 301 - Moved Permanently,
// 302 - Found, Moved Temporarily
// 304 - not modified
// 307 - Temporary Redirect
} else if (status === 400) {
// Probably is a validation error
} else if (status === 403 || status === 401) {
// 401 - Forbidden
// 403 - Unauthorized
} else if (status === 404) {
// Not Found
} else if (status >= 500) {
// Server error
}
return response
}
// Could save you some time:
// function checkStatus (response: Response): Response {
// const {status} = response
// if (status >= 200 && status < 300) {
// // Everything is ok
// } else if (status >= 300 && status < 400) {
// // 300 - Multiple Choices
// // 301 - Moved Permanently,
// // 302 - Found, Moved Temporarily
// // 304 - not modified
// // 307 - Temporary Redirect
// } else if (status === 400) {
// // Probably is a validation error
// } else if (status === 403 || status === 401) {
// // 401 - Forbidden
// // 403 - Unauthorized
// } else if (status === 404) {
// // Not Found
// } else if (status >= 500) {
// // Server error
// }
// return response
// }

0 comments on commit dd3110b

Please sign in to comment.