我需要像这样的东西在香草节点js,有人可以引导我通过吗?
import { ExceptionFilter, Catch, ArgumentsHost, HttpException } from '@nestjs/common';
import { Request, Response } from 'express';
@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter {
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest<Request>();
const status = exception.getStatus();
response
.status(status)
.json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
});
}
}
1条答案
按热度按时间1zmg4dgp1#
您可以编写如下所示的过滤器中间件/拦截器来处理自定义错误,但是,您必须更新当前实现以匹配解决方案