export type JsonPrimitive = string | number | boolean | null; export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }; export type CatalogErrorDefinition = { code: string; status: number; i18nKey: string; message?: string; }; export const catalogRegistry = Object.freeze({}) satisfies Record; export class CatalogError extends Error { readonly code: string; readonly status: number; readonly i18nKey: string; readonly details?: Record; constructor(definition: CatalogErrorDefinition, details?: Record) { super(definition.message ?? definition.code); this.name = "CatalogError"; this.code = definition.code; this.status = definition.status; this.i18nKey = definition.i18nKey; this.details = details; } } export const foundationErrors = { forbidden: { code: "foundation.forbidden", status: 403, i18nKey: "foundation.errors.forbidden" }, notFound: { code: "foundation.not_found", status: 404, i18nKey: "foundation.errors.notFound" }, idempotencyConflict: { code: "foundation.idempotency_conflict", status: 409, i18nKey: "foundation.errors.idempotencyConflict", }, idempotencyInProgress: { code: "foundation.idempotency_in_progress", status: 409, i18nKey: "foundation.errors.idempotencyInProgress", }, } as const satisfies Record; export function toPinoLogObject(error: unknown): Record { if (error instanceof CatalogError) { return { error: { name: error.name, message: error.message, code: error.code, status: error.status, i18nKey: error.i18nKey, details: error.details } }; } if (error instanceof Error) { return { error: { name: error.name, message: error.message, stack: error.stack } }; } return { error }; }