mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-16 13:06:54 +00:00
* First pass at handling API failure. * Bity saga logic upgrade. * Reusable response.ok logic. Small optimization to array join. * Flow fixes. * Streamlined some error handling, moved types.
25 lines
531 B
JavaScript
25 lines
531 B
JavaScript
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;
|
|
}
|
|
}
|
|
|
|
export function parseJSON(response) {
|
|
return response.json();
|
|
}
|
|
|
|
export async function handleJSONResponse(response, errorMessage) {
|
|
if (response.ok) {
|
|
const json = await response.json();
|
|
return json;
|
|
}
|
|
if (errorMessage) {
|
|
throw new Error(errorMessage);
|
|
}
|
|
return false;
|
|
}
|