2017-07-31 23:14:30 +00:00
|
|
|
export function checkHttpStatus(response) {
|
|
|
|
if (response.status >= 200 && response.status < 300) {
|
|
|
|
return response;
|
|
|
|
} else {
|
|
|
|
let error = new Error(response.statusText);
|
|
|
|
error.response = response;
|
|
|
|
throw error;
|
2017-07-04 03:28:56 +00:00
|
|
|
}
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 23:14:30 +00:00
|
|
|
export function parseJSON(response) {
|
|
|
|
return response.json();
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
2017-08-31 16:30:46 +00: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;
|
|
|
|
}
|