-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy patherrors.ts
More file actions
32 lines (29 loc) · 1.13 KB
/
Copy patherrors.ts
File metadata and controls
32 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ── Typed Error Factory ──────────────────────────────────────────────────────
// All daemon API errors use a consistent shape: { error: string, code: ApiErrorCode }.
// The panel can narrow on `code` to show user-friendly messages.
export type ApiErrorCode =
| 'invalid_json'
| 'container_not_found'
| 'path_traversal'
| 'rate_limit_exceeded'
| 'unauthorized'
| 'hmac_expired'
| 'hmac_invalid'
| 'nonce_replayed'
| 'missing_nonce'
| 'missing_hmac_headers'
| 'access_denied'
| 'internal_error';
export interface ApiError {
error: string;
code: ApiErrorCode;
}
// Type-safe error factory. Uses `satisfies` to ensure the shape matches
// without widening the type. The panel can match on `code` to display
// contextual error messages instead of raw daemon strings.
export function apiError(code: ApiErrorCode, message: string, status: number): Response {
return new Response(JSON.stringify({ error: message, code } satisfies ApiError), {
status,
headers: { 'Content-Type': 'application/json' },
});
}