Skip to content

Commit

Permalink
fix: getTokenById return token nil, make panic (#1728)
Browse files Browse the repository at this point in the history
* fix:getTokenById return token nil, make panic

* chore: remove useless err check

---------

Co-authored-by: JustSong <[email protected]>
  • Loading branch information
qinguoyi and songquanpeng authored Sep 21, 2024
1 parent cba8240 commit 3a27c90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions controller/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ func GetSubscription(c *gin.Context) {
if config.DisplayTokenStatEnabled {
tokenId := c.GetInt(ctxkey.TokenId)
token, err = model.GetTokenById(tokenId)
expiredTime = token.ExpiredTime
remainQuota = token.RemainQuota
usedQuota = token.UsedQuota
if err == nil {
expiredTime = token.ExpiredTime
remainQuota = token.RemainQuota
usedQuota = token.UsedQuota
}
} else {
userId := c.GetInt(ctxkey.Id)
remainQuota, err = model.GetUserQuota(userId)
Expand Down
6 changes: 3 additions & 3 deletions model/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ func PreConsumeTokenQuota(tokenId int, quota int64) (err error) {

func PostConsumeTokenQuota(tokenId int, quota int64) (err error) {
token, err := GetTokenById(tokenId)
if err != nil {
return err
}
if quota > 0 {
err = DecreaseUserQuota(token.UserId, quota)
} else {
err = IncreaseUserQuota(token.UserId, -quota)
}
if err != nil {
return err
}
if !token.UnlimitedQuota {
if quota > 0 {
err = DecreaseTokenQuota(tokenId, quota)
Expand Down

0 comments on commit 3a27c90

Please sign in to comment.