Skip to content

Instantly share code, notes, and snippets.

@ThomasSchoenbeck
Last active December 5, 2021 16:11
Show Gist options
  • Save ThomasSchoenbeck/22408c7d633bc939e2058ae21279f3bd to your computer and use it in GitHub Desktop.
Save ThomasSchoenbeck/22408c7d633bc939e2058ae21279f3bd to your computer and use it in GitHub Desktop.
export function handleJsonResponse(response: any) {
return response.json()
.then((json: any) => {
if (!response.ok) { // if changed, all API calls will break
const error = Object.assign({}, json, {
data: json,
status: response.status,
statusText: response.statusText,
});
return Promise.reject(error);
}
return json;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment