fix: fix token validation exception handling #901
* fix: fix exception handling 1. add error log for ValidateUserToken 2. update en.json * chore: update log --------- Co-authored-by: seven.yu <seven.yu@dji.com> Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
parent
cbf8f07747
commit
6227eee5bc
@ -86,6 +86,7 @@
|
|||||||
"该令牌已过期": "The token has expired",
|
"该令牌已过期": "The token has expired",
|
||||||
"该令牌额度已用尽": "The token quota has been used up",
|
"该令牌额度已用尽": "The token quota has been used up",
|
||||||
"无效的令牌": "Invalid token",
|
"无效的令牌": "Invalid token",
|
||||||
|
"令牌验证失败": "Token verification failed",
|
||||||
"id 或 userId 为空!": "id or userId is empty!",
|
"id 或 userId 为空!": "id or userId is empty!",
|
||||||
"quota 不能为负数!": "quota cannot be negative!",
|
"quota 不能为负数!": "quota cannot be negative!",
|
||||||
"令牌额度不足": "Insufficient token quota",
|
"令牌额度不足": "Insufficient token quota",
|
||||||
|
@ -38,7 +38,13 @@ func ValidateUserToken(key string) (token *Token, err error) {
|
|||||||
return nil, errors.New("未提供令牌")
|
return nil, errors.New("未提供令牌")
|
||||||
}
|
}
|
||||||
token, err = CacheGetTokenByKey(key)
|
token, err = CacheGetTokenByKey(key)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
|
common.SysError("CacheGetTokenByKey failed: " + err.Error())
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return nil, errors.New("无效的令牌")
|
||||||
|
}
|
||||||
|
return nil, errors.New("令牌验证失败")
|
||||||
|
}
|
||||||
if token.Status == common.TokenStatusExhausted {
|
if token.Status == common.TokenStatusExhausted {
|
||||||
return nil, errors.New("该令牌额度已用尽")
|
return nil, errors.New("该令牌额度已用尽")
|
||||||
} else if token.Status == common.TokenStatusExpired {
|
} else if token.Status == common.TokenStatusExpired {
|
||||||
@ -69,8 +75,6 @@ func ValidateUserToken(key string) (token *Token, err error) {
|
|||||||
return nil, errors.New("该令牌额度已用尽")
|
return nil, errors.New("该令牌额度已用尽")
|
||||||
}
|
}
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
|
||||||
return nil, errors.New("无效的令牌")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTokenByIds(id int, userId int) (*Token, error) {
|
func GetTokenByIds(id int, userId int) (*Token, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user