dorfteich/packages/shared/src/api-error.ts
Claude Fable 5 c12acbdb2c Add NestJS API skeleton with config, logging, and /healthz
apps/api boots a NestJS application with: Zod-validated environment
configuration (schema in @dorfteich/shared, fails fast listing every
invalid variable), structured pino request logging via nestjs-pino
(pretty in development, JSON otherwise, auth headers redacted), a
global exception filter producing the uniform ApiErrorBody shape, and
GET /api/v1/healthz. Vitest runs Nest through SWC for decorator
metadata; supertest covers healthz and the 404 error shape.

Closes #2

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 19:10:07 +02:00

20 lines
600 B
TypeScript

/**
* Uniform error body returned by every non-2xx api response. `code` is a
* stable, machine-readable identifier that doubles as the i18n key suffix
* (`errors.<code>`); `message` is an English fallback for clients without
* translations. Optional `details` carries field-level validation issues.
*/
export interface ApiErrorBody {
code: string;
message: string;
details?: Record<string, string[]>;
}
export function apiError(
code: string,
message: string,
details?: ApiErrorBody['details'],
): ApiErrorBody {
return details ? { code, message, details } : { code, message };
}