Readable errors for non-JSON API responses; gitignore test transcripts

This commit is contained in:
Ian Gulliver
2026-10-14 23:02:38 -07:00
parent f5333586fe
commit fbfc3d1923
13 changed files with 12 additions and 111 deletions
+4
View File
@@ -84,6 +84,10 @@ export async function request<M extends Method, P extends PathsWith<M>>(
if (res.status === 204) {
return undefined as Result<Op<P, M>>;
}
if (!res.headers.get("Content-Type")?.startsWith("application/json")) {
const text = (await res.text()).trim();
throw new ApiError(res.status, `${res.status} ${res.statusText}${text ? `: ${text}` : ""}`);
}
const data = await res.json();
if (!res.ok) {
throw new ApiError(res.status, (data as Schemas["Error"]).message);