Эх сурвалжийг харах

优化错误处理,移除错误信息返回,统一返回操作失败的消息以增强安全性和用户体验。

wuyi 3 сар өмнө
parent
commit
70dbc32bda

+ 7 - 14
src/controllers/file.controller.ts

@@ -40,8 +40,7 @@ export class FileController {
       })
     } catch (error) {
       return reply.code(500).send({
-        message: 'ZIP文件上传失败',
-        error: error instanceof Error ? error.message : '未知错误'
+        message: 'ZIP文件上传失败'
       })
     }
   }
@@ -74,8 +73,7 @@ export class FileController {
       })
     } catch (error) {
       return reply.code(500).send({
-        message: '文件上传失败',
-        error: error instanceof Error ? error.message : '未知错误'
+        message: '文件上传失败'
       })
     }
   }
@@ -108,8 +106,7 @@ export class FileController {
       })
     } catch (error) {
       return reply.code(500).send({
-        message: '图片上传失败',
-        error: error instanceof Error ? error.message : '未知错误'
+        message: '图片上传失败'
       })
     }
   }
@@ -141,8 +138,7 @@ export class FileController {
       })
     } catch (error) {
       return reply.code(500).send({
-        message: '文档上传失败',
-        error: error instanceof Error ? error.message : '未知错误'
+        message: '文档上传失败'
       })
     }
   }
@@ -167,8 +163,7 @@ export class FileController {
       }
     } catch (error) {
       return reply.code(500).send({
-        message: '文件删除失败',
-        error: error instanceof Error ? error.message : '未知错误'
+        message: '文件删除失败'
       })
     }
   }
@@ -188,8 +183,7 @@ export class FileController {
       })
     } catch (error) {
       return reply.code(500).send({
-        message: '获取文件URL失败',
-        error: error instanceof Error ? error.message : '未知错误'
+        message: '获取文件URL失败'
       })
     }
   }
@@ -234,8 +228,7 @@ export class FileController {
       return reply.send(fileBuffer)
     } catch (error) {
       return reply.code(500).send({
-        message: '文件下载失败',
-        error: error instanceof Error ? error.message : '未知错误'
+        message: '文件下载失败'
       })
     }
   }

+ 7 - 7
src/controllers/finance.controller.ts

@@ -28,7 +28,7 @@ export class FinanceController {
       const finance = await this.financeService.create(request.body)
       return reply.code(201).send(finance)
     } catch (error) {
-      return reply.code(500).send({ message: '创建财务记录失败', error })
+      return reply.code(500).send({ message: '创建财务记录失败' })
     }
   }
 
@@ -54,7 +54,7 @@ export class FinanceController {
       const result = await this.financeService.findAll(request.query)
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '获取财务记录列表失败', error })
+      return reply.code(500).send({ message: '获取财务记录列表失败' })
     }
   }
 
@@ -72,7 +72,7 @@ export class FinanceController {
       const updatedRecord = await this.financeService.update(updateData)
       return reply.send(updatedRecord)
     } catch (error) {
-      return reply.code(500).send({ message: '更新财务记录失败', error })
+      return reply.code(500).send({ message: '更新财务记录失败' })
     }
   }
 
@@ -89,7 +89,7 @@ export class FinanceController {
       await this.financeService.delete(id)
       return reply.send({ message: '财务记录已删除' })
     } catch (error) {
-      return reply.code(500).send({ message: '删除财务记录失败', error })
+      return reply.code(500).send({ message: '删除财务记录失败' })
     }
   }
 
@@ -106,7 +106,7 @@ export class FinanceController {
       await this.financeService.hardDelete(id)
       return reply.send({ message: '财务记录已永久删除' })
     } catch (error) {
-      return reply.code(500).send({ message: '永久删除财务记录失败', error })
+      return reply.code(500).send({ message: '永久删除财务记录失败' })
     }
   }
 
@@ -130,7 +130,7 @@ export class FinanceController {
       const updatedRecord = await this.financeService.updateStatus(id, status, rejectReason)
       return reply.send(updatedRecord)
     } catch (error) {
-      return reply.code(500).send({ message: '更新财务状态失败', error })
+      return reply.code(500).send({ message: '更新财务状态失败' })
     }
   }
 
@@ -143,7 +143,7 @@ export class FinanceController {
       const statistics = await this.financeService.getStatistics(startDate, endDate)
       return reply.send(statistics)
     } catch (error) {
-      return reply.code(500).send({ message: '获取统计数据失败', error })
+      return reply.code(500).send({ message: '获取统计数据失败' })
     }
   }
 }

+ 6 - 6
src/controllers/income-records.controller.ts

@@ -58,7 +58,7 @@ export class IncomeRecordsController {
       const incomeRecord = await this.incomeRecordsService.create(request.body)
       return reply.code(201).send(incomeRecord)
     } catch (error) {
-      return reply.code(500).send({ message: '创建收入记录失败', error })
+      return reply.code(500).send({ message: '创建收入记录失败' })
     }
   }
 
@@ -92,7 +92,7 @@ export class IncomeRecordsController {
       const result = await this.incomeRecordsService.findAll(request.query)
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '获取收入记录列表失败', error })
+      return reply.code(500).send({ message: '获取收入记录列表失败' })
     }
   }
 
@@ -113,7 +113,7 @@ export class IncomeRecordsController {
       const updatedRecord = await this.incomeRecordsService.update(updateData)
       return reply.send(updatedRecord)
     } catch (error) {
-      return reply.code(500).send({ message: '更新收入记录失败', error })
+      return reply.code(500).send({ message: '更新收入记录失败' })
     }
   }
 
@@ -130,7 +130,7 @@ export class IncomeRecordsController {
       await this.incomeRecordsService.delete(id)
       return reply.send({ message: '收入记录已删除' })
     } catch (error) {
-      return reply.code(500).send({ message: '删除收入记录失败', error })
+      return reply.code(500).send({ message: '删除收入记录失败' })
     }
   }
 
@@ -147,7 +147,7 @@ export class IncomeRecordsController {
       await this.incomeRecordsService.hardDelete(id)
       return reply.send({ message: '收入记录已永久删除' })
     } catch (error) {
-      return reply.code(500).send({ message: '永久删除收入记录失败', error })
+      return reply.code(500).send({ message: '永久删除收入记录失败' })
     }
   }
 
@@ -172,7 +172,7 @@ export class IncomeRecordsController {
       const statistics = await this.incomeRecordsService.getStatistics(startDate, endDate, agentId, userId)
       return reply.send(statistics)
     } catch (error) {
-      return reply.code(500).send({ message: '获取统计数据失败', error })
+      return reply.code(500).send({ message: '获取统计数据失败' })
     }
   }
 }

+ 16 - 16
src/controllers/member.controller.ts

@@ -51,7 +51,7 @@ export class MemberController {
         token
       })
     } catch (error) {
-      return reply.code(500).send({ message: '创建游客失败', error })
+      return reply.code(500).send({ message: '创建游客失败' })
     }
   }
 
@@ -86,7 +86,7 @@ export class MemberController {
         return reply.code(400).send({ message: errorMessage })
       }
 
-      return reply.code(500).send({ message: '更新游客失败', error: errorMessage })
+      return reply.code(500).send({ message: '更新游客失败' })
     }
   }
 
@@ -147,7 +147,7 @@ export class MemberController {
       if (errorMessage.includes('已被使用')) {
         return reply.code(400).send({ message: errorMessage })
       }
-      return reply.code(500).send({ message: '注册失败', error: errorMessage })
+      return reply.code(500).send({ message: '注册失败' })
     }
   }
 
@@ -176,7 +176,7 @@ export class MemberController {
         token
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '登录失败' })
     }
   }
 
@@ -199,7 +199,7 @@ export class MemberController {
         vipExpireTime: member.vipExpireTime
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '获取会员信息失败' })
     }
   }
 
@@ -213,7 +213,7 @@ export class MemberController {
       await this.userService.resetPassword(request.user.id, password)
       return reply.send({ message: '密码重置成功' })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '重置密码失败' })
     }
   }
 
@@ -237,7 +237,7 @@ export class MemberController {
         }
       })
     } catch (error) {
-      return reply.code(500).send({ message: '更新VIP等级失败', error })
+      return reply.code(500).send({ message: '更新VIP等级失败' })
     }
   }
 
@@ -278,7 +278,7 @@ export class MemberController {
 
       return reply.code(201).send({ message: '创建会员成功' })
     } catch (error) {
-      return reply.code(500).send({ message: '创建会员失败', error })
+      return reply.code(500).send({ message: '创建会员失败' })
     }
   }
 
@@ -330,7 +330,7 @@ export class MemberController {
         }
       })
     } catch (error) {
-      return reply.code(500).send({ message: '查询会员失败', error })
+      return reply.code(500).send({ message: '查询会员失败' })
     }
   }
 
@@ -342,7 +342,7 @@ export class MemberController {
 
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '查询会员列表失败', error })
+      return reply.code(500).send({ message: '查询会员列表失败' })
     }
   }
 
@@ -397,7 +397,7 @@ export class MemberController {
         }
       })
     } catch (error) {
-      return reply.code(500).send({ message: '更新会员失败', error })
+      return reply.code(500).send({ message: '更新会员失败' })
     }
   }
 
@@ -416,7 +416,7 @@ export class MemberController {
 
       return reply.send({ message: '删除会员成功' })
     } catch (error) {
-      return reply.code(500).send({ message: '删除会员失败', error })
+      return reply.code(500).send({ message: '删除会员失败' })
     }
   }
 
@@ -425,7 +425,7 @@ export class MemberController {
       const members = await this.memberService.findAllMembers()
       return reply.send({ members })
     } catch (error) {
-      return reply.code(500).send({ message: '获取所有会员失败', error })
+      return reply.code(500).send({ message: '获取所有会员失败' })
     }
   }
 
@@ -457,7 +457,7 @@ export class MemberController {
         }
       })
     } catch (error) {
-      return reply.code(500).send({ message: '更新会员状态失败', error })
+      return reply.code(500).send({ message: '更新会员状态失败' })
     }
   }
 
@@ -468,7 +468,7 @@ export class MemberController {
 
       return reply.send({ message: '更新最后登录时间成功' })
     } catch (error) {
-      return reply.code(500).send({ message: '更新最后登录时间失败', error })
+      return reply.code(500).send({ message: '更新最后登录时间失败' })
     }
   }
 
@@ -482,7 +482,7 @@ export class MemberController {
         statusStats
       })
     } catch (error) {
-      return reply.code(500).send({ message: '获取统计数据失败', error })
+      return reply.code(500).send({ message: '获取统计数据失败' })
     }
   }
 }

+ 7 - 7
src/controllers/payment.controller.ts

@@ -38,7 +38,7 @@ export class PaymentController {
       const result = await this.paymentService.createPaymentOrder({ userId, type, ip })
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '创建支付订单失败', error })
+      return reply.code(500).send({ message: '创建支付订单失败' })
     }
   }
 
@@ -59,7 +59,7 @@ export class PaymentController {
       const result = await this.paymentService.createSinglePaymentOrder({ resourceId, userId, ip })
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '创建单片购买订单失败', error })
+      return reply.code(500).send({ message: '创建单片购买订单失败' })
     }
   }
 
@@ -68,7 +68,7 @@ export class PaymentController {
       await this.paymentService.handlePaymentNotify(request.query)
       return reply.send('success')
     } catch (error) {
-      return reply.code(500).send('Failed to handle payment notification')
+      return reply.code(500).send({ message: '处理支付通知失败' })
     }
   }
 
@@ -93,7 +93,7 @@ export class PaymentController {
       const result = await this.paymentService.queryOrder({ trade_no, out_trade_no })
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send('Failed to query payment order')
+      return reply.code(500).send({ message: '查询支付订单失败' })
     }
   }
 
@@ -104,7 +104,7 @@ export class PaymentController {
       const result = await this.paymentService.userQueryOrder(user.id, orderNo, resourceId)
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send('Failed to query user order')
+      return reply.code(500).send({ message: '查询用户订单失败' })
     }
   }
 
@@ -115,7 +115,7 @@ export class PaymentController {
       const result = await this.paymentService.userSingleQuery(user.id, resourceId)
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send('Failed to query user single query')
+      return reply.code(500).send({ message: '查询用户单片信息失败' })
     }
   }
 
@@ -126,7 +126,7 @@ export class PaymentController {
       const result = await this.paymentService.userSingleList(user.id, { page, size, resourceId })
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send('Failed to query user single list')
+      return reply.code(500).send({ message: '查询用户单片列表失败' })
     }
   }
 }

+ 6 - 6
src/controllers/promotion-link.controller.ts

@@ -35,7 +35,7 @@ export class PromotionLinkController {
       const promotionLink = await this.promotionLinkService.create(request.body)
       return reply.code(201).send(promotionLink)
     } catch (error) {
-      return reply.code(500).send({ message: '创建推广链接失败', error })
+      return reply.code(500).send({ message: '创建推广链接失败' })
     }
   }
 
@@ -65,7 +65,7 @@ export class PromotionLinkController {
       const result = await this.promotionLinkService.findAll(request.query)
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '获取推广链接列表失败', error })
+      return reply.code(500).send({ message: '获取推广链接列表失败' })
     }
   }
 
@@ -86,7 +86,7 @@ export class PromotionLinkController {
       const updatedLink = await this.promotionLinkService.update(updateData)
       return reply.send(updatedLink)
     } catch (error) {
-      return reply.code(500).send({ message: '更新推广链接失败', error })
+      return reply.code(500).send({ message: '更新推广链接失败' })
     }
   }
 
@@ -103,7 +103,7 @@ export class PromotionLinkController {
       await this.promotionLinkService.delete(id)
       return reply.send({ message: '推广链接已删除' })
     } catch (error) {
-      return reply.code(500).send({ message: '删除推广链接失败', error })
+      return reply.code(500).send({ message: '删除推广链接失败' })
     }
   }
 
@@ -113,7 +113,7 @@ export class PromotionLinkController {
       const links = await this.promotionLinkService.findByType(type)
       return reply.send(links)
     } catch (error) {
-      return reply.code(500).send({ message: '获取指定类型推广链接失败', error })
+      return reply.code(500).send({ message: '获取指定类型推广链接失败' })
     }
   }
 
@@ -122,7 +122,7 @@ export class PromotionLinkController {
       const statistics = await this.promotionLinkService.getStatistics()
       return reply.send(statistics)
     } catch (error) {
-      return reply.code(500).send({ message: '获取统计数据失败', error })
+      return reply.code(500).send({ message: '获取统计数据失败' })
     }
   }
 }

+ 12 - 12
src/controllers/sys-config.controller.ts

@@ -25,7 +25,7 @@ export class SysConfigController {
       const config = await this.sysConfigService.create(request.body)
       return reply.code(201).send(config)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -34,7 +34,7 @@ export class SysConfigController {
       const config = await this.sysConfigService.update(request.params.name, request.body, request.body.teamId)
       return reply.send(config)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -43,7 +43,7 @@ export class SysConfigController {
       await this.sysConfigService.delete(request.params.name)
       return reply.send({ success: true })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -52,7 +52,7 @@ export class SysConfigController {
       const config = await this.sysConfigService.getSysConfig(request.params.name)
       return reply.send(config)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -62,7 +62,7 @@ export class SysConfigController {
       const configs = await this.sysConfigService.list(Number(page), Number(size), name, type, teamId)
       return reply.send(configs)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -71,7 +71,7 @@ export class SysConfigController {
       const types = await this.sysConfigService.getConfigTypes()
       return reply.send(types)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -88,7 +88,7 @@ export class SysConfigController {
       const config = await this.sysConfigService.createTeamConfig(body, userId, userRole, teamId)
       return reply.code(201).send(config)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -105,7 +105,7 @@ export class SysConfigController {
       const config = await this.sysConfigService.updateTeamConfig(name, body, userId, userRole, teamId)
       return reply.send(config)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -122,7 +122,7 @@ export class SysConfigController {
       await this.sysConfigService.deleteTeamConfig(name, userId, userRole, teamId)
       return reply.send({ success: true })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -144,7 +144,7 @@ export class SysConfigController {
       )
       return reply.send(config)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -165,7 +165,7 @@ export class SysConfigController {
       )
       return reply.send(configs)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 
@@ -178,7 +178,7 @@ export class SysConfigController {
       const configs = await this.sysConfigService.getUserTeamConfigs(userId)
       return reply.send(configs)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '操作失败' })
     }
   }
 }

+ 0 - 1
src/controllers/team-domain.controller.ts

@@ -72,7 +72,6 @@ export class TeamDomainController {
       const result = await this.teamDomainService.findAll(request.query)
       return reply.send(result)
     } catch (error) {
-      console.error(error)
       return reply.code(500).send({ message: '获取团队域名列表失败' })
     }
   }

+ 7 - 7
src/controllers/team-members.controller.ts

@@ -33,7 +33,7 @@ export class TeamMembersController {
       const teamMember = await this.teamMembersService.create(request.body, request.user.id)
       return reply.code(201).send(teamMember)
     } catch (error) {
-      return reply.code(500).send({ message: '创建团队成员失败', error })
+      return reply.code(500).send({ message: '创建团队成员失败' })
     }
   }
 
@@ -60,7 +60,7 @@ export class TeamMembersController {
       const result = await this.teamMembersService.findAll(request.query)
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '获取团队成员列表失败', error })
+      return reply.code(500).send({ message: '获取团队成员列表失败' })
     }
   }
 
@@ -81,7 +81,7 @@ export class TeamMembersController {
       const updatedMember = await this.teamMembersService.update(updateData)
       return reply.send(updatedMember)
     } catch (error) {
-      return reply.code(500).send({ message: '更新团队成员失败', error })
+      return reply.code(500).send({ message: '更新团队成员失败' })
     }
   }
 
@@ -98,7 +98,7 @@ export class TeamMembersController {
       await this.teamMembersService.delete(id)
       return reply.send({ message: '团队成员已删除' })
     } catch (error) {
-      return reply.code(500).send({ message: '删除团队成员失败', error })
+      return reply.code(500).send({ message: '删除团队成员失败' })
     }
   }
 
@@ -115,7 +115,7 @@ export class TeamMembersController {
       const updatedMember = await this.teamMembersService.updateRevenue(id, amount, type)
       return reply.send(updatedMember)
     } catch (error) {
-      return reply.code(500).send({ message: '更新团队成员收入失败', error })
+      return reply.code(500).send({ message: '更新团队成员收入失败' })
     }
   }
 
@@ -124,7 +124,7 @@ export class TeamMembersController {
       await this.teamMembersService.resetTodayRevenue()
       return reply.send({ message: '今日收入已重置' })
     } catch (error) {
-      return reply.code(500).send({ message: '重置今日收入失败', error })
+      return reply.code(500).send({ message: '重置今日收入失败' })
     }
   }
 
@@ -133,7 +133,7 @@ export class TeamMembersController {
       const statistics = await this.teamMembersService.getStatistics()
       return reply.send(statistics)
     } catch (error) {
-      return reply.code(500).send({ message: '获取统计数据失败', error })
+      return reply.code(500).send({ message: '获取统计数据失败' })
     }
   }
 }

+ 8 - 8
src/controllers/team.controller.ts

@@ -15,7 +15,7 @@ export class TeamController {
       const team = await this.teamService.create(request.body, request.user.id)
       return reply.code(201).send(team)
     } catch (error) {
-      return reply.code(500).send({ message: '创建团队失败', error })
+      return reply.code(500).send({ message: '创建团队失败' })
     }
   }
 
@@ -41,7 +41,7 @@ export class TeamController {
       const result = await this.teamService.findAll(request.query)
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send({ message: '获取团队列表失败', error })
+      return reply.code(500).send({ message: '获取团队列表失败' })
     }
   }
 
@@ -59,7 +59,7 @@ export class TeamController {
       const updatedTeam = await this.teamService.update(updateData)
       return reply.send(updatedTeam)
     } catch (error) {
-      return reply.code(500).send({ message: '更新团队失败', error })
+      return reply.code(500).send({ message: '更新团队失败' })
     }
   }
 
@@ -76,7 +76,7 @@ export class TeamController {
       await this.teamService.delete(id)
       return reply.send({ message: '团队已删除' })
     } catch (error) {
-      return reply.code(500).send({ message: '删除团队失败', error })
+      return reply.code(500).send({ message: '删除团队失败' })
     }
   }
 
@@ -93,7 +93,7 @@ export class TeamController {
       const updatedTeam = await this.teamService.updateRevenue(id, amount, type)
       return reply.send(updatedTeam)
     } catch (error) {
-      return reply.code(500).send({ message: '更新团队收入失败', error })
+      return reply.code(500).send({ message: '更新团队收入失败' })
     }
   }
 
@@ -102,7 +102,7 @@ export class TeamController {
       const statistics = await this.teamService.getStatistics()
       return reply.send(statistics)
     } catch (error) {
-      return reply.code(500).send({ message: '获取统计数据失败', error })
+      return reply.code(500).send({ message: '获取统计数据失败' })
     }
   }
 
@@ -115,7 +115,7 @@ export class TeamController {
       const statistics = await this.teamService.getTeamStatistics(user.id)
       return reply.send(statistics)
     } catch (error) {
-      return reply.code(500).send({ message: '获取统计数据失败', error })
+      return reply.code(500).send({ message: '获取统计数据失败' })
     }
   }
 
@@ -124,7 +124,7 @@ export class TeamController {
       const teams = await this.teamService.getTeams()
       return reply.send(teams)
     } catch (error) {
-      return reply.code(500).send({ message: '获取团队失败', error })
+      return reply.code(500).send({ message: '获取团队失败' })
     }
   }
 

+ 8 - 8
src/controllers/user.controller.ts

@@ -37,7 +37,7 @@ export class UserController {
         token
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '注册失败' })
     }
   }
 
@@ -71,7 +71,7 @@ export class UserController {
         token
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '登录失败' })
     }
   }
 
@@ -84,7 +84,7 @@ export class UserController {
         role: user.role
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '获取用户信息失败' })
     }
   }
 
@@ -98,7 +98,7 @@ export class UserController {
       await this.userService.resetPassword(request.user.id, password)
       return reply.send({ message: '密码重置成功' })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '重置密码失败' })
     }
   }
 
@@ -119,7 +119,7 @@ export class UserController {
 
       return reply.send(result)
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '获取用户列表失败' })
     }
   }
 
@@ -149,7 +149,7 @@ export class UserController {
         }
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '创建用户失败' })
     }
   }
 
@@ -182,7 +182,7 @@ export class UserController {
         }
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '更新用户失败' })
     }
   }
 
@@ -196,7 +196,7 @@ export class UserController {
         users: childUsers
       })
     } catch (error) {
-      return reply.code(500).send(error)
+      return reply.code(500).send({ message: '获取子用户失败' })
     }
   }
 }

+ 1 - 2
src/middlewares/auth.middleware.ts

@@ -6,8 +6,7 @@ export async function authenticate(request: FastifyRequest, reply: FastifyReply)
     await request.jwtVerify()
   } catch (err) {
     reply.code(401).send({
-      message: 'Unauthorized',
-      error: err
+      message: 'Unauthorized'
     })
   }
 }

+ 5 - 5
src/services/file.service.ts

@@ -70,7 +70,7 @@ export class FileService {
 
     // 验证文件大小
     if (options.maxSize && buffer.length > options.maxSize) {
-      throw new Error(`文件大小超过限制: ${buffer.length} > ${options.maxSize}`)
+      throw new Error('操作失败')
     }
 
     // 生成文件名
@@ -108,7 +108,7 @@ export class FileService {
 
       return uploadResult
     } catch (error) {
-      throw new Error(`ZIP文件上传失败: ${error instanceof Error ? error.message : '未知错误'}`)
+      throw new Error('操作失败')
     }
   }
 
@@ -128,12 +128,12 @@ export class FileService {
   ): Promise<UploadResult> {
     // 验证文件类型
     if (options.allowedTypes && !options.allowedTypes.includes(mimeType)) {
-      throw new Error(`不支持的文件类型: ${mimeType}`)
+      throw new Error('操作失败')
     }
 
     // 验证文件大小
     if (options.maxSize && buffer.length > options.maxSize) {
-      throw new Error(`文件大小超过限制: ${buffer.length} > ${options.maxSize}`)
+      throw new Error('操作失败')
     }
 
     // 生成文件名
@@ -171,7 +171,7 @@ export class FileService {
 
       return uploadResult
     } catch (error) {
-      throw new Error(`文件上传失败: ${error instanceof Error ? error.message : '未知错误'}`)
+      throw new Error('操作失败')
     }
   }
 

+ 1 - 1
src/services/payment.service.ts

@@ -220,7 +220,7 @@ export class PaymentService {
         })
       } catch (incomeError) {
         this.app.log.error('Failed to create income record:', incomeError)
-        throw new Error('Failed to create income record')
+        throw new Error('操作失败')
       }
 
       return {

+ 1 - 1
src/services/sys-config.service.ts

@@ -95,7 +95,7 @@ export class SysConfigService {
     }
     const existingConfig = await this.sysConfigRepository.findOne({ where })
     if (existingConfig) {
-      throw new Error('配置名称已存在')
+        throw new Error('操作失败')
     }
     const config = this.sysConfigRepository.create(data)
     return await this.sysConfigRepository.save(config)

+ 1 - 1
src/services/team-members.service.ts

@@ -20,7 +20,7 @@ export class TeamMembersService {
 
     const existingUser = await this.userService.findByName(teamMemberData.name)
     if (existingUser) {
-      throw new Error('团队成员已存在')
+        throw new Error('操作失败')
     }
 
     const userPassword = password || 'password123'