Handling token exceptions

pull/236/head
wenxu12345 2 years ago
parent 86c26793b7
commit 1a3b5d018a

@ -292,9 +292,30 @@ func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request, operation
query := r.URL.Query()
if len(query["token"]) != 0 && len(query["sendID"]) != 0 && len(query["platformID"]) != 0 {
if ok, err, msg := token_verify.WsVerifyToken(query["token"][0], query["sendID"][0], query["platformID"][0], operationID); !ok {
if errors.Is(err, constant.ErrTokenExpired) {
status = int(constant.ErrTokenExpired.ErrCode)
}
if errors.Is(err, constant.ErrTokenInvalid) {
status = int(constant.ErrTokenInvalid.ErrCode)
}
if errors.Is(err, constant.ErrTokenMalformed) {
status = int(constant.ErrTokenMalformed.ErrCode)
}
if errors.Is(err, constant.ErrTokenNotValidYet) {
status = int(constant.ErrTokenNotValidYet.ErrCode)
}
if errors.Is(err, constant.ErrTokenUnknown) {
status = int(constant.ErrTokenUnknown.ErrCode)
}
if errors.Is(err, constant.ErrTokenKicked) {
status = int(constant.ErrTokenKicked.ErrCode)
}
if errors.Is(err, constant.ErrTokenDifferentPlatformID) {
status = int(constant.ErrTokenDifferentPlatformID.ErrCode)
}
if errors.Is(err, constant.ErrTokenDifferentUserID) {
status = int(constant.ErrTokenDifferentUserID.ErrCode)
}
//switch errors.Cause(err) {
//case constant.ErrTokenExpired:
// status = int(constant.ErrTokenExpired.ErrCode)

@ -180,18 +180,18 @@ func ParseTokenGetUserID(token string, operationID string) (error, string) {
func ParseToken(tokensString, operationID string) (claims *Claims, err error) {
claims, err = GetClaimFromToken(tokensString)
if err != nil {
if errors.Is(err, constant.ErrTokenUnknown) {
errMsg := "GetClaimFromToken failed ErrTokenUnknown " + err.Error()
log.Error(operationID, errMsg)
}
info := err.(constant.ErrInfo)
log.Error(operationID, "detail info , ", info.ErrCode, info.ErrMsg)
e := errors.Unwrap(err)
if errors.Is(e, constant.ErrTokenUnknown) {
errMsg := "ParseToken failed ErrTokenUnknown " + e.Error()
log.Error(operationID, errMsg)
}
//if errors.Is(err, constant.ErrTokenUnknown) {
// errMsg := "GetClaimFromToken failed ErrTokenUnknown " + err.Error()
// log.Error(operationID, errMsg)
//}
//info := err.(constant.ErrInfo)
//log.Error(operationID, "detail info , ", info.ErrCode, info.ErrMsg)
//
//e := errors.Unwrap(err)
//if errors.Is(e, constant.ErrTokenUnknown) {
// errMsg := "ParseToken failed ErrTokenUnknown " + e.Error()
// log.Error(operationID, errMsg)
//}
log.NewError(operationID, "token validate err", err.Error(), tokensString, "type ", reflect.TypeOf(err), "type2: ", reflect.TypeOf(e))
return nil, utils.Wrap(err, "")
@ -260,15 +260,15 @@ func WsVerifyToken(token, uid string, platformID string, operationID string) (bo
argMsg := "token: " + token + " operationID: " + operationID + " userID: " + uid + " platformID: " + platformID
claims, err := ParseToken(token, operationID)
if err != nil {
if errors.Is(err, constant.ErrTokenUnknown) {
errMsg := "ParseToken failed ErrTokenUnknown " + err.Error()
log.Error(operationID, errMsg)
}
e := errors.Unwrap(err)
if errors.Is(e, constant.ErrTokenUnknown) {
errMsg := "ParseToken failed ErrTokenUnknown " + e.Error()
log.Error(operationID, errMsg)
}
//if errors.Is(err, constant.ErrTokenUnknown) {
// errMsg := "ParseToken failed ErrTokenUnknown " + err.Error()
// log.Error(operationID, errMsg)
//}
//e := errors.Unwrap(err)
//if errors.Is(e, constant.ErrTokenUnknown) {
// errMsg := "ParseToken failed ErrTokenUnknown " + e.Error()
// log.Error(operationID, errMsg)
//}
errMsg := "parse token err " + err.Error() + argMsg
return false, utils.Wrap(err, errMsg), errMsg

Loading…
Cancel
Save