express-typeorm-rest-boilerplate
Version:
Boilerplate code to get started with building RESTful API Services
18 lines (16 loc) • 435 B
text/typescript
import { Response } from 'express';
export class ErrorHandler extends Error {
public statusCode: number;
public message: string;
constructor(statusCode: number, message: string) {
super();
this.statusCode = statusCode;
this.message = message;
}
}
export const handleError = (err: ErrorHandler, res: Response) => {
const { statusCode, message } = err;
res.status(statusCode).json({
error: message,
});
};