refactor(media): share http error handling

This commit is contained in:
Peter Steinberger
2026-02-16 00:32:16 +00:00
parent d8691ff4ec
commit 652318e56a
4 changed files with 15 additions and 18 deletions

View File

@@ -47,3 +47,12 @@ export async function readErrorResponse(res: Response): Promise<string | undefin
return undefined;
}
}
export async function assertOkOrThrowHttpError(res: Response, label: string): Promise<void> {
if (res.ok) {
return;
}
const detail = await readErrorResponse(res);
const suffix = detail ? `: ${detail}` : "";
throw new Error(`${label} (HTTP ${res.status})${suffix}`);
}