fix: 暴露开发环境 API 异常详情
This commit is contained in:
1 parent
b4657ccdc0
commit
ccf1c6bc31
1 file changed
+6
-1
@@ -26,7 +26,12 @@ export class ApiExceptionFilter implements ExceptionFilter {
|
||||
const response = context.getResponse<FastifyReply>();
|
||||
const request = context.getRequest<FastifyRequest>();
|
||||
const status = exception instanceof HttpException ? exception.getStatus() : 500;
|
||||
const detail = exception instanceof HttpException ? exception.getResponse() : "服务器内部错误";
|
||||
if (!(exception instanceof HttpException)) console.error("api unhandled error", exception);
|
||||
const detail = exception instanceof HttpException
|
||||
? exception.getResponse()
|
||||
: process.env.NODE_ENV === "development" && exception instanceof Error
|
||||
? exception.message
|
||||
: "服务器内部错误";
|
||||
response.status(status).send({
|
||||
data: null,
|
||||
error: {
|
||||
|
||||
Reference in new issue
Block a user