2017-12-30 20:29:04 +00:00
|
|
|
import indexOf from 'lodash/indexOf';
|
2017-12-11 17:44:53 +00:00
|
|
|
|
|
|
|
export const filter = (i: any, arr: any[]) => {
|
|
|
|
return -1 !== indexOf(arr, i) ? true : false;
|
|
|
|
};
|
|
|
|
|
2017-12-19 22:46:34 +00:00
|
|
|
export function checkHttpStatus(response: Response) {
|
2017-07-31 23:14:30 +00:00
|
|
|
if (response.status >= 200 && response.status < 300) {
|
|
|
|
return response;
|
|
|
|
} else {
|
2017-09-26 03:41:11 +00:00
|
|
|
return new Error(response.statusText);
|
2017-07-04 03:28:56 +00:00
|
|
|
}
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 22:46:34 +00:00
|
|
|
export function parseJSON(response: Response) {
|
2017-07-31 23:14:30 +00:00
|
|
|
return response.json();
|
2017-04-12 05:04:27 +00:00
|
|
|
}
|
2017-08-31 16:30:46 +00:00
|
|
|
|
2017-12-19 22:46:34 +00:00
|
|
|
export async function handleJSONResponse(response: Response, errorMessage: string) {
|
2017-08-31 16:30:46 +00:00
|
|
|
if (response.ok) {
|
2017-09-26 03:41:11 +00:00
|
|
|
return await response.json();
|
2017-08-31 16:30:46 +00:00
|
|
|
}
|
|
|
|
if (errorMessage) {
|
|
|
|
throw new Error(errorMessage);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|