Readable errors for non-JSON API responses; gitignore test transcripts
This commit is contained in:
Vendored
+4
@@ -36,6 +36,10 @@ export async function request(method, path, opts = {}) {
|
||||
if (res.status === 204) {
|
||||
return undefined;
|
||||
}
|
||||
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.message);
|
||||
|
||||
Reference in New Issue
Block a user