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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user