refactor: Improve quota error messages with formatted quota display
This commit is contained in:
@@ -95,11 +95,11 @@ func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usag
|
|||||||
quota := calculateAudioQuota(quotaInfo)
|
quota := calculateAudioQuota(quotaInfo)
|
||||||
|
|
||||||
if userQuota < quota {
|
if userQuota < quota {
|
||||||
return errors.New(fmt.Sprintf("用户额度不足,剩余额度为 %d", userQuota))
|
return fmt.Errorf("user quota is not enough, user quota: %s, need quota: %s", common.FormatQuota(userQuota), common.FormatQuota(quota))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !token.UnlimitedQuota && token.RemainQuota < quota {
|
if !token.UnlimitedQuota && token.RemainQuota < quota {
|
||||||
return errors.New(fmt.Sprintf("令牌额度不足,剩余额度为 %d", token.RemainQuota))
|
return fmt.Errorf("token quota is not enough, token remain quota: %s, need quota: %s", common.FormatQuota(token.RemainQuota), common.FormatQuota(quota))
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PostConsumeQuota(relayInfo, quota, 0, false)
|
err = PostConsumeQuota(relayInfo, quota, 0, false)
|
||||||
@@ -262,7 +262,7 @@ func PreConsumeTokenQuota(relayInfo *relaycommon.RelayInfo, quota int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !relayInfo.TokenUnlimited && token.RemainQuota < quota {
|
if !relayInfo.TokenUnlimited && token.RemainQuota < quota {
|
||||||
return errors.New("令牌额度不足")
|
return fmt.Errorf("token quota is not enough, token remain quota: %s, need quota: %s", common.FormatQuota(token.RemainQuota), common.FormatQuota(quota))
|
||||||
}
|
}
|
||||||
err = model.DecreaseTokenQuota(relayInfo.TokenId, relayInfo.TokenKey, quota)
|
err = model.DecreaseTokenQuota(relayInfo.TokenId, relayInfo.TokenKey, quota)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user