fix: 修正停复机接口错误码,网关失败不再返回模糊的内部服务器错误
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m13s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m13s
- 单卡停复机:网关错误从 CodeInternalError(2001) 改为 CodeGatewayError(1110),前端可看到具体失败原因 - 单卡停复机:DB 更新裸返 GORM error 改为 CodeDatabaseError(2002) 包装 - 设备复机:全部卡失败时错误码从 CodeInternalError 改为 CodeGatewayError
This commit is contained in:
@@ -973,7 +973,7 @@ func (s *Service) StartDevice(ctx context.Context, deviceID uint) error {
|
|||||||
|
|
||||||
// 全部失败时返回 error
|
// 全部失败时返回 error
|
||||||
if successCount == 0 && lastErr != nil {
|
if successCount == 0 && lastErr != nil {
|
||||||
return errors.Wrap(errors.CodeInternalError, lastErr, "设备复机失败")
|
return errors.Wrap(errors.CodeGatewayError, lastErr, "设备复机失败,所有卡均复机失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -264,15 +264,18 @@ func (s *StopResumeService) ManualStopCard(ctx context.Context, iccid string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := s.stopCardWithRetry(ctx, card); err != nil {
|
if err := s.stopCardWithRetry(ctx, card); err != nil {
|
||||||
return errors.Wrap(errors.CodeInternalError, err, "调网关停机失败")
|
return errors.Wrap(errors.CodeGatewayError, err, "调用运营商停机失败,请稍后重试")
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
return s.db.WithContext(ctx).Model(card).Updates(map[string]any{
|
if err := s.db.WithContext(ctx).Model(card).Updates(map[string]any{
|
||||||
"network_status": constants.NetworkStatusOffline,
|
"network_status": constants.NetworkStatusOffline,
|
||||||
"stopped_at": now,
|
"stopped_at": now,
|
||||||
"stop_reason": constants.StopReasonManual,
|
"stop_reason": constants.StopReasonManual,
|
||||||
}).Error
|
}).Error; err != nil {
|
||||||
|
return errors.Wrap(errors.CodeDatabaseError, err, "更新卡状态失败")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManualStartCard 手动复机单张卡(通过ICCID)
|
// ManualStartCard 手动复机单张卡(通过ICCID)
|
||||||
@@ -300,13 +303,16 @@ func (s *StopResumeService) ManualStartCard(ctx context.Context, iccid string) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := s.resumeCardWithRetry(ctx, card); err != nil {
|
if err := s.resumeCardWithRetry(ctx, card); err != nil {
|
||||||
return errors.Wrap(errors.CodeInternalError, err, "调网关复机失败")
|
return errors.Wrap(errors.CodeGatewayError, err, "调用运营商复机失败,请稍后重试")
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
return s.db.WithContext(ctx).Model(card).Updates(map[string]any{
|
if err := s.db.WithContext(ctx).Model(card).Updates(map[string]any{
|
||||||
"network_status": constants.NetworkStatusOnline,
|
"network_status": constants.NetworkStatusOnline,
|
||||||
"resumed_at": now,
|
"resumed_at": now,
|
||||||
"stop_reason": "",
|
"stop_reason": "",
|
||||||
}).Error
|
}).Error; err != nil {
|
||||||
|
return errors.Wrap(errors.CodeDatabaseError, err, "更新卡状态失败")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user