FEAT-3: fix unhandled ApiError rejections (catch in form submits + dev unhandledrejection guard, ApiError carries path)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-06 00:36:14 +02:00
parent e76554342b
commit c6699a9592
5 changed files with 48 additions and 7 deletions

View File

@@ -10,11 +10,14 @@ export const API_BASE_URL: string =
export class ApiError extends Error {
readonly status: number | null
/** The request path that failed (for diagnostics/logging). */
readonly path?: string
constructor(message: string, status: number | null) {
constructor(message: string, status: number | null, path?: string) {
super(message)
this.name = 'ApiError'
this.status = status
this.path = path
}
}
@@ -32,11 +35,11 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
...init,
})
} catch {
throw new ApiError(de.api.errors.network, null)
throw new ApiError(de.api.errors.network, null, path)
}
if (!response.ok) {
throw new ApiError(errorMessageFor(response.status), response.status)
throw new ApiError(errorMessageFor(response.status), response.status, path)
}
if (response.status === 204) {