/** * Typed service-layer error carrying an HTTP status so both auth fronts * (ext API-key routes and internal session routes) map errors identically. */ export class PipelineError extends Error { status: number; details?: unknown; constructor(status: number, message: string, details?: unknown) { super(message); this.name = "PipelineError"; this.status = status; this.details = details; } } export function toErrorResponse(err: unknown): { body: { error: string; details?: unknown }; status: number } { if (err instanceof PipelineError) { return { body: { error: err.message, ...(err.details !== undefined ? { details: err.details } : {}) }, status: err.status, }; } console.error("[render-pipeline]", err); return { body: { error: "Internal server error" }, status: 500 }; }