feat(token): enhance error handling in ValidateUserToken for better clarity

This commit is contained in:
CaIon
2025-12-22 18:01:38 +08:00
parent afd9c29ace
commit 42109c5840

View File

@@ -112,7 +112,12 @@ func ValidateUserToken(key string) (token *Token, err error) {
}
return token, nil
}
return nil, errors.New("无效的令牌")
common.SysLog("ValidateUserToken: failed to get token: " + err.Error())
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("无效的令牌")
} else {
return nil, errors.New("无效的令牌,数据库查询出错,请联系管理员")
}
}
func GetTokenByIds(id int, userId int) (*Token, error) {