import { HttpException, HttpStatus } from '@nestjs/common'; import { Response } from 'express'; import { RESTError, RESTResponseBody } from '../models/wrappers/rest-wrapper.class'; class HandledException extends HttpException { constructor(private readonly _errors: RESTError[], private readonly _statusCode?: HttpStatus) { super({ errors: _errors }, _statusCode || HttpStatus.BAD_REQUEST); } public send(response: Response) { const responseBody = RESTResponseBody.fail(this._errors, this._statusCode || HttpStatus.BAD_REQUEST); response.status(this._statusCode).json(responseBody); } public getErrors(){ return this._errors; } } export { HandledException };