feat: add Express API base structure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Consultoria AS
2026-01-22 01:50:22 +00:00
parent 830e98625d
commit af617627a4
7 changed files with 154 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import type { Request, Response, NextFunction } from 'express';
export class AppError extends Error {
constructor(
public statusCode: number,
public message: string,
public isOperational = true
) {
super(message);
Object.setPrototypeOf(this, AppError.prototype);
}
}
export function errorMiddleware(
err: Error,
req: Request,
res: Response,
next: NextFunction
) {
if (err instanceof AppError) {
return res.status(err.statusCode).json({
status: 'error',
message: err.message,
});
}
console.error('Unhandled error:', err);
return res.status(500).json({
status: 'error',
message: 'Internal server error',
});
}