src/core/filters/http-exception.filter.ts
Basic filter for processing unhabdled HTTP exceptions
ExceptionFilter
Methods |
catch | ||||||||||||
catch(exception: HttpException, host: ArgumentsHost)
|
||||||||||||
Defined in src/core/filters/http-exception.filter.ts:13
|
||||||||||||
Exception handling method
Parameters :
Returns :
void
|
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from "@nestjs/common";
/**
* Basic filter for processing unhabdled HTTP exceptions
*/
@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
/**
* Exception handling method
* @param exception Execution object currently being processed
* @param host Arguments host utility object
*/
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const status = exception.getStatus();
response.status(status).json({
status: status,
message: exception.message,
});
}
}