Last active
December 5, 2021 16:11
-
-
Save ThomasSchoenbeck/22408c7d633bc939e2058ae21279f3bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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