|
|
@@ -11,13 +11,6 @@ export const isAdminZhong = (req: any, res: any, next: any) => {
|
|
|
};
|
|
|
|
|
|
// 2:----------------捕捉路由中的错误
|
|
|
-
|
|
|
-// 这个好像没啥用
|
|
|
-// export const asyncHandler = (fn: any) => (req: any, res: any, next: any) => {
|
|
|
-// // 确保 fn 返回的 Promise 被捕获,任何异常都会通过 catch 传递给 next
|
|
|
-// Promise.resolve(fn(req, res, next)).catch(next);
|
|
|
-// };
|
|
|
-
|
|
|
export const errorHandler = (err: any, req: any, res: any, next: any) => {
|
|
|
// 记录错误日志,便于后端排查
|
|
|
// console.error('错误处理中间件捕获到异常:', err);
|
|
|
@@ -31,7 +24,7 @@ export const errorHandler = (err: any, req: any, res: any, next: any) => {
|
|
|
method: req.method,
|
|
|
url: req.originalUrl,
|
|
|
userName,
|
|
|
- apiDescription: req.apiDescription || '',
|
|
|
+ apiDescription: req.apiDescription || '-',
|
|
|
ip: ipLocResFu(req), // 获取IP
|
|
|
userAgent: req.get('User-Agent'), // 获取User-Agent
|
|
|
};
|