Skip to content

Scheduling infrastructure for absolutely everyone.

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

alannnc5a0cef7fb972
diff --git a/packages/lib/errors.ts b/packages/lib/errors.ts
index c6731699be1..6bec1e8a50d 100644
--- a/packages/lib/errors.ts
+++ b/packages/lib/errors.ts
@@ -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);
}