| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import { NextResponse } from "next/server"; |
|
|
| interface ApiError { |
| code: string; |
| message: string; |
| correlation_id?: string; |
| details?: Record<string, unknown>; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function errorResponse( |
| code: string, |
| message: string, |
| status: number, |
| opts?: { correlationId?: string; details?: Record<string, unknown> } |
| ): NextResponse { |
| const body: { error: ApiError } = { |
| error: { |
| code, |
| message, |
| ...(opts?.correlationId ? { correlation_id: opts.correlationId } : {}), |
| ...(opts?.details ? { details: opts.details } : {}), |
| }, |
| }; |
| return NextResponse.json(body, { status }); |
| } |
|
|
| |
| |
| |
| export function successResponse(data: unknown, status = 200): NextResponse { |
| return NextResponse.json(data, { status }); |
| } |
|
|
| |
| |
| |
| export const ErrorCodes = { |
| |
| AUTH_001: "AUTH_001", |
| AUTH_002: "AUTH_002", |
| AUTH_003: "AUTH_003", |
|
|
| |
| VALIDATION_001: "VALIDATION_001", |
| VALIDATION_002: "VALIDATION_002", |
|
|
| |
| SERVER_001: "SERVER_001", |
| SERVER_002: "SERVER_002", |
| SERVER_003: "SERVER_003", |
|
|
| |
| SECURITY_001: "SECURITY_001", |
| SECURITY_002: "SECURITY_002", |
|
|
| |
| RESOURCE_001: "RESOURCE_001", |
| RESOURCE_002: "RESOURCE_002", |
| } as const; |
|
|