Files
smart_grid_iot/server/src/middleware/error.middleware.ts
T
andyesfly 3d7eb12103 feat: 初始化智能物联网设备管理系统前后端基础项目
完成项目整体结构搭建,包含:
1. 前端Vue3+TS+Vite+Antd项目基础配置与核心依赖
2. 后端MidwayJS+TypeORM+JWT权限认证框架
3. 完整的用户、角色、权限、日志数据库表结构
4. 核心业务模块API与基础服务实现
5. 全局样式、路由、状态管理配置
2026-05-28 16:23:15 +08:00

34 lines
704 B
TypeScript

import { Middleware } from '@midwayjs/core';
import { Context, NextFunction } from '@midwayjs/koa';
@Middleware()
export class ErrorMiddleware {
static getName(): string {
return 'error';
}
resolve() {
return async (ctx: Context, next: NextFunction) => {
try {
await next();
} catch (err: any) {
console.error('全局错误捕获:', err);
const status = err.status || 500;
const message = err.message || '服务器内部错误';
ctx.status = status;
ctx.body = {
code: status,
message: message,
data: null,
};
}
};
}
ignore(ctx: Context): boolean {
return false;
}
}