MyCrypto/common/api/utils.ts
HenryNguyen5 f39787152e Fix Miscellaneous Types (#635)
* Add repo wide prettier command to prepush

* Make config file explict, remove formatAll to prepush

* Fix react router typings

* Add more typings

* Fix event typings,  fix transition children
2017-12-19 16:46:34 -06:00

28 lines
628 B
TypeScript

import { indexOf } from 'lodash';
export const filter = (i: any, arr: any[]) => {
return -1 !== indexOf(arr, i) ? true : false;
};
export function checkHttpStatus(response: Response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
return new Error(response.statusText);
}
}
export function parseJSON(response: Response) {
return response.json();
}
export async function handleJSONResponse(response: Response, errorMessage: string) {
if (response.ok) {
return await response.json();
}
if (errorMessage) {
throw new Error(errorMessage);
}
return false;
}