mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-07 06:43:41 +08:00
feat: 优化令牌无效提示
This commit is contained in:
@@ -47,7 +47,9 @@ func ValidateUserToken(key string) (token *Token, err error) {
|
|||||||
token, err = CacheGetTokenByKey(key)
|
token, err = CacheGetTokenByKey(key)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if token.Status == common.TokenStatusExhausted {
|
if token.Status == common.TokenStatusExhausted {
|
||||||
return nil, errors.New("该令牌额度已用尽 token.Status == common.TokenStatusExhausted " + key)
|
keyPrefix := key[:3]
|
||||||
|
keySuffix := key[len(key)-3:]
|
||||||
|
return nil, errors.New("该令牌额度已用尽 TokenStatusExhausted[sk-" + keyPrefix + "***" + keySuffix + "]")
|
||||||
} else if token.Status == common.TokenStatusExpired {
|
} else if token.Status == common.TokenStatusExpired {
|
||||||
return nil, errors.New("该令牌已过期")
|
return nil, errors.New("该令牌已过期")
|
||||||
}
|
}
|
||||||
@@ -73,7 +75,9 @@ func ValidateUserToken(key string) (token *Token, err error) {
|
|||||||
common.SysError("failed to update token status" + err.Error())
|
common.SysError("failed to update token status" + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, errors.New(fmt.Sprintf("%s 该令牌额度已用尽 !token.UnlimitedQuota && token.RemainQuota = %d", token.Key, token.RemainQuota))
|
keyPrefix := key[:3]
|
||||||
|
keySuffix := key[len(key)-3:]
|
||||||
|
return nil, errors.New(fmt.Sprintf("[sk-%s***%s] 该令牌额度已用尽 !token.UnlimitedQuota && token.RemainQuota = %d", keyPrefix, keySuffix, token.RemainQuota))
|
||||||
}
|
}
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user