| 20 | ...clientErrors, |
| 21 | ...webErrors, |
| 22 | } as const; |
| 23 | |
| 24 | /** |
| 25 | * Send a catalog error as an HTTP response |
| 26 | */ |
| 27 | export function sendCatalogError({ |
| 28 | reply, |
| 29 | status, |
| 30 | code, |
| 31 | detail, |
| 32 | }: { |
| 33 | reply: FastifyReply; |
| 34 | status: number; |
| 35 | code: ErrorCode; |
| 36 | detail?: string; |
| 37 | }): FastifyReply { |
| 38 | const err = getError(code) ?? |
| 39 | getError("UNEXPECTED_ERROR") ?? { |
| 40 | code: "UNEXPECTED_ERROR", |
| 41 | message: "Unexpected error", |
| 42 | }; |
| 43 | return applyProblemContentType({ reply }) |
| 44 | .code(status) |
| 45 | .send( |
| 46 | toCatalogProblem({ code: err.code, detail, message: err.message, status }) |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | export function sendServerCatalogError({ |
| 51 | request, |
| 52 | reply, |
| 53 | code, |
| 54 | error, |
| 55 | }: { |
| 56 | request: FastifyRequest; |
| 57 | reply: FastifyReply; |
| 58 | code: ErrorCode; |
| 59 | error?: unknown; |
| 60 | }): FastifyReply { |
| 61 | captureError({ |