然后把异常定义一下
This commit is contained in:
parent
7aea5a1308
commit
0e349316f8
|
@ -1,6 +1,16 @@
|
||||||
import { ArgumentsHost, Catch, ExceptionFilter } from '@nestjs/common';
|
import { ArgumentsHost, Catch, ExceptionFilter, HttpException } from '@nestjs/common';
|
||||||
|
|
||||||
@Catch()
|
@Catch(HttpException)
|
||||||
export class DemoFilter<T> implements ExceptionFilter {
|
export class DemoFilter<T> implements ExceptionFilter {
|
||||||
catch(exception: T, host: ArgumentsHost) {}
|
catch(exception: HttpException, host: ArgumentsHost) {
|
||||||
|
const ctx = host.switchToHttp();
|
||||||
|
const response = ctx.getResponse();
|
||||||
|
const request = ctx.getRequest();
|
||||||
|
const status = exception.getStatus();
|
||||||
|
|
||||||
|
response.status(status).json({
|
||||||
|
statusCode: status,
|
||||||
|
path: request.url,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue