Function
errorBody
(
code: string,
details: Record<string, unknown> = {},
)
Source from the content-addressed store, hash-verified
| 87 | } |
| 88 | |
| 89 | function errorBody( |
| 90 | code: string, |
| 91 | details: Record<string, unknown> = {}, |
| 92 | ): { |
| 93 | status: number; |
| 94 | body: unknown; |
| 95 | } { |
| 96 | const statusMap: Record<string, number> = { |
| 97 | AUTH_REQUIRED: 401, |
| 98 | AUTH_FORBIDDEN: 403, |
| 99 | NOT_FOUND: 404, |
| 100 | VALIDATION_ERROR: 400, |
| 101 | CONFLICT: 409, |
| 102 | RATE_LIMITED: 429, |
| 103 | INTERNAL: 500, |
| 104 | UNAVAILABLE: 503, |
| 105 | }; |
| 106 | return { |
| 107 | status: statusMap[code] ?? 400, |
| 108 | body: { |
| 109 | error: { |
| 110 | code, |
| 111 | message: `Error: ${code}`, |
| 112 | nextAction: 'do something', |
| 113 | requestId: 'req_test', |
| 114 | details, |
| 115 | }, |
| 116 | }, |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | const instantSleep = () => Promise.resolve(); |
| 121 | |
Tested by
no test coverage detected