@@ -3770,12 +3770,33 @@ func (s *Store) ApplyAccountEnabled(dbID int64, enabled bool) bool {
37703770 return true
37713771}
37723772
3773+ func normalizeAccountErrorMessage (errorMsg string , fallback string ) string {
3774+ errorMsg = strings .TrimSpace (errorMsg )
3775+ if errorMsg == "" {
3776+ errorMsg = strings .TrimSpace (fallback )
3777+ }
3778+ if len (errorMsg ) > 500 {
3779+ errorMsg = errorMsg [:500 ]
3780+ }
3781+ return errorMsg
3782+ }
3783+
37733784// MarkCooldown 标记账号进入冷却,并持久化到数据库
37743785func (s * Store ) MarkCooldown (acc * Account , duration time.Duration , reason string ) {
3786+ s .markCooldown (acc , duration , reason , "" )
3787+ }
3788+
3789+ // MarkCooldownWithError 标记账号进入冷却,并同时记录本次上游错误详情。
3790+ func (s * Store ) MarkCooldownWithError (acc * Account , duration time.Duration , reason string , errorMsg string ) {
3791+ s .markCooldown (acc , duration , reason , errorMsg )
3792+ }
3793+
3794+ func (s * Store ) markCooldown (acc * Account , duration time.Duration , reason string , errorMsg string ) {
37753795 if acc == nil {
37763796 return
37773797 }
37783798
3799+ errorMsg = normalizeAccountErrorMessage (errorMsg , "" )
37793800 now := time .Now ()
37803801 acc .mu .Lock ()
37813802 switch reason {
@@ -3801,6 +3822,9 @@ func (s *Store) MarkCooldown(acc *Account, duration time.Duration, reason string
38013822 acc .HealthTier = HealthTierRisky
38023823 }
38033824 }
3825+ if errorMsg != "" {
3826+ acc .ErrorMsg = errorMsg
3827+ }
38043828 acc .recomputeSchedulerLocked (atomic .LoadInt64 (& s .maxConcurrency ))
38053829 acc .mu .Unlock ()
38063830
@@ -3815,7 +3839,13 @@ func (s *Store) MarkCooldown(acc *Account, duration time.Duration, reason string
38153839
38163840 ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Second )
38173841 defer cancel ()
3818- if err := s .db .SetCooldown (ctx , acc .DBID , reason , until ); err != nil {
3842+ var err error
3843+ if errorMsg != "" {
3844+ err = s .db .SetCooldownWithError (ctx , acc .DBID , reason , until , errorMsg )
3845+ } else {
3846+ err = s .db .SetCooldown (ctx , acc .DBID , reason , until )
3847+ }
3848+ if err != nil {
38193849 log .Printf ("[账号 %d] 持久化冷却状态失败: %v" , acc .DBID , err )
38203850 }
38213851}
@@ -3917,13 +3947,7 @@ func (s *Store) MarkError(acc *Account, errorMsg string) {
39173947 return
39183948 }
39193949
3920- errorMsg = strings .TrimSpace (errorMsg )
3921- if errorMsg == "" {
3922- errorMsg = "账号测试失败"
3923- }
3924- if len (errorMsg ) > 500 {
3925- errorMsg = errorMsg [:500 ]
3926- }
3950+ errorMsg = normalizeAccountErrorMessage (errorMsg , "账号测试失败" )
39273951
39283952 now := time .Now ()
39293953 acc .mu .Lock ()
0 commit comments