Improve error handling

This commit is contained in:
Dominic Ferrando
2026-06-23 19:49:26 -04:00
parent 1ca0fe308d
commit 449b08971f
5 changed files with 116 additions and 137 deletions
+2 -24
View File
@@ -1,7 +1,7 @@
export type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;
export const formatSlug = (name: string): string => {
@@ -13,25 +13,3 @@ export const formatSlug = (name: string): string => {
.replace(/--+/g, "-") // collapse multiple dashes
.replace(/^([^a-z0-9_])/, "_$1"); // if it starts with an invalid char, prefix underscore
};
export class FetchError extends Error {
public payload: Object | undefined;
constructor(
message: string,
public response: Response,
) {
super(message);
this.name = "FetchError";
}
async parse() {
try {
this.payload = (await this.response.clone().json()) as Object;
} catch {
this.payload = await this.response.text().catch(() => undefined);
} finally {
return this.payload;
}
}
}