Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Pure API error types/helpers (no $env / $app) — safe for node:test.
|
||||
*/
|
||||
|
||||
export class ApiError extends Error {
|
||||
status: number;
|
||||
body: unknown;
|
||||
|
||||
constructor(message: string, status: number, body: unknown) {
|
||||
super(message);
|
||||
this.name = "ApiError";
|
||||
this.status = status;
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
|
||||
/** HTTP status phrases that should not be shown as form copy. */
|
||||
const OPAQUE_HTTP_STATUS = new Set([
|
||||
"",
|
||||
"bad request",
|
||||
"unauthorized",
|
||||
"forbidden",
|
||||
"not found",
|
||||
"conflict",
|
||||
"too many requests",
|
||||
"internal server error",
|
||||
"service unavailable",
|
||||
"method not allowed",
|
||||
"request failed"
|
||||
]);
|
||||
|
||||
function isOpaqueHttpStatus(msg: string): boolean {
|
||||
return OPAQUE_HTTP_STATUS.has(msg.trim().toLowerCase());
|
||||
}
|
||||
|
||||
/** User-visible message from an `api()` / `apiDownload()` catch value (or any thrown Error). */
|
||||
export function failureMessage(err: unknown, fallback: string): string {
|
||||
if (err instanceof Error) {
|
||||
const msg = err.message.trim();
|
||||
if (msg && !isOpaqueHttpStatus(msg)) return msg;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
Reference in New Issue
Block a user