fix/error-handling-with-proper-status (#3453)

* Add conditional on error handling

* Fix return type for handleError

Co-authored-by: Omar López <zomars@me.com>
This commit is contained in:
alannnc
2022-07-20 14:02:00 -06:00
committed by GitHub
co-authored by Omar López
parent 13d13c71c6
commit 5a0cef7fb9
+8 -2
View File
@@ -11,7 +11,10 @@ export function getErrorFromUnknown(cause: unknown): Error & { statusCode?: numb
}
export function handleErrorsJson(response: Response) {
if (!response.ok) {
if (response.status === 204) {
return new Promise((resolve) => resolve({}));
}
if (!response.ok && response.status < 200 && response.status >= 300) {
response.json().then(console.log);
throw Error(response.statusText);
}
@@ -19,7 +22,10 @@ export function handleErrorsJson(response: Response) {
}
export function handleErrorsRaw(response: Response) {
if (!response.ok) {
if (response.status === 204) {
return {};
}
if (!response.ok && response.status < 200 && response.status >= 300) {
response.text().then(console.log);
throw Error(response.statusText);
}