mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:02:42 +00:00
refactor(media): share http error handling
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user