| 84 | const isClientApiError = (error: unknown): boolean => |
| 85 | error instanceof ApiError && |
| 86 | error.statusCode >= 400 && |
| 87 | error.statusCode < 500; |
| 88 | |
| 89 | /* |
| 90 | * Resolve the final HTTP status BEFORE the log line so observability |
| 91 | * surfaces what the client actually saw. Elysia's `set.status` is the |
| 92 | * pre-handler default; an `ApiError` overrides it to its own |
| 93 | * `statusCode`, and Elysia-thrown codes map below. |
| 94 | */ |
| 95 | const resolveFinalStatus = (code: string, error: unknown): number => { |
| 96 | if (error instanceof ApiError) { |
| 97 | return error.statusCode; |
| 98 | } |
| 99 | |
| 100 | switch (code) { |
| 101 | case ElysiaErrorCodes.NOT_FOUND: |
| 102 | return 404; |
| 103 | case ElysiaErrorCodes.VALIDATION: |
| 104 | case ElysiaErrorCodes.PARSE: |
| 105 | return 400; |