MCPcopy Create free account
hub / github.com/blockmatic/basilic / mapHttpStatusToErrorCode

Function mapHttpStatusToErrorCode

apps/api/src/lib/catalogs/mapper.ts:22–58  ·  view source on GitHub ↗
(statusCode?: number)

Source from the content-addressed store, hash-verified

20 ...clientErrors,
21 ...webErrors,
22} as const;
23
24/**
25 * Send a catalog error as an HTTP response
26 */
27export 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
50export 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({

Callers 1

error-handler.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected