File size: 282 Bytes
c84f41e
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
import { Context } from 'koa';

// 统一的错误处理中间件函数
export const handleControllerError = async (ctx: Context, error: any) => {
  console.error('Controller Error:', error);

  ctx.status = error.statusCode || 500;
  ctx.body = {
    error: error.message,
  };
};