fix:getTokenById return token nil, make panic

This commit is contained in:
qinguoyi
2024-08-10 11:21:07 +08:00
parent f9774698e9
commit 6073440919
2 changed files with 12 additions and 7 deletions

View File

@@ -254,11 +254,14 @@ func PreConsumeTokenQuota(tokenId int, quota int64) (err error) {
func PostConsumeTokenQuota(tokenId int, quota int64) (err error) {
token, err := GetTokenById(tokenId)
if quota > 0 {
err = DecreaseUserQuota(token.UserId, quota)
} else {
err = IncreaseUserQuota(token.UserId, -quota)
if err == nil {
if quota > 0 {
err = DecreaseUserQuota(token.UserId, quota)
} else {
err = IncreaseUserQuota(token.UserId, -quota)
}
}
if err != nil {
return err
}