2017-07-31 18:14:30 -05:00
|
|
|
export function checkHttpStatus(response) {
|
|
|
|
if (response.status >= 200 && response.status < 300) {
|
|
|
|
return response;
|
|
|
|
} else {
|
2017-09-24 19:06:28 -07:00
|
|
|
const error = new Error(response.statusText);
|
|
|
|
// TODO: why assign response?
|
|
|
|
// error.response = response;
|
2017-07-31 18:14:30 -05:00
|
|
|
throw error;
|
2017-07-03 22:28:56 -05:00
|
|
|
}
|
2017-04-12 00:04:27 -05:00
|
|
|
}
|
|
|
|
|
2017-07-31 18:14:30 -05:00
|
|
|
export function parseJSON(response) {
|
|
|
|
return response.json();
|
2017-04-12 00:04:27 -05:00
|
|
|
}
|
2017-08-31 10:30:46 -06:00
|
|
|
|
|
|
|
export async function handleJSONResponse(response, errorMessage) {
|
|
|
|
if (response.ok) {
|
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
if (errorMessage) {
|
|
|
|
throw new Error(errorMessage);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|