error
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
package msggateway
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/log"
|
||||
pbChat "OpenIM/pkg/proto/msg"
|
||||
sdkws "OpenIM/pkg/proto/sdkws"
|
||||
"OpenIM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var MaxPullMsgNum = 100
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/errs"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
@@ -10,35 +10,35 @@ func httpError(ctx *UserConnContext, err error) {
|
||||
code := http.StatusUnauthorized
|
||||
ctx.SetHeader("Sec-Websocket-Version", "13")
|
||||
ctx.SetHeader("ws_err_msg", err.Error())
|
||||
if errors.Is(err, constant.ErrTokenExpired) {
|
||||
code = int(constant.ErrTokenExpired.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenExpired) {
|
||||
code = errs.ErrTokenExpired.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenInvalid) {
|
||||
code = int(constant.ErrTokenInvalid.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenInvalid) {
|
||||
code = errs.ErrTokenInvalid.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenMalformed) {
|
||||
code = int(constant.ErrTokenMalformed.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenMalformed) {
|
||||
code = errs.ErrTokenMalformed.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenNotValidYet) {
|
||||
code = int(constant.ErrTokenNotValidYet.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenNotValidYet) {
|
||||
code = errs.ErrTokenNotValidYet.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenUnknown) {
|
||||
code = int(constant.ErrTokenUnknown.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenUnknown) {
|
||||
code = errs.ErrTokenUnknown.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenKicked) {
|
||||
code = int(constant.ErrTokenKicked.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenKicked) {
|
||||
code = errs.ErrTokenKicked.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenDifferentPlatformID) {
|
||||
code = int(constant.ErrTokenDifferentPlatformID.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenDifferentPlatformID) {
|
||||
code = errs.ErrTokenDifferentPlatformID.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenDifferentUserID) {
|
||||
code = int(constant.ErrTokenDifferentUserID.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenDifferentUserID) {
|
||||
code = errs.ErrTokenDifferentUserID.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrConnOverMaxNumLimit) {
|
||||
code = int(constant.ErrConnOverMaxNumLimit.ErrCode)
|
||||
if errors.Is(err, errs.ErrConnOverMaxNumLimit) {
|
||||
code = errs.ErrConnOverMaxNumLimit.Code()
|
||||
}
|
||||
if errors.Is(err, constant.ErrConnArgsErr) {
|
||||
code = int(constant.ErrConnArgsErr.ErrCode)
|
||||
if errors.Is(err, errs.ErrConnArgsErr) {
|
||||
code = errs.ErrConnArgsErr.Code()
|
||||
}
|
||||
ctx.ErrReturn(err.Error(), code)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package new
|
||||
import (
|
||||
"OpenIM/pkg/common/constant"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/errs"
|
||||
"OpenIM/pkg/utils"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -131,7 +132,7 @@ func (ws *WsServer) unregisterClient(client *Client) {
|
||||
func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
context := newContext(w, r)
|
||||
if ws.onlineUserConnNum >= ws.wsMaxConnNum {
|
||||
httpError(context, constant.ErrConnOverMaxNumLimit)
|
||||
httpError(context, errs.ErrConnOverMaxNumLimit)
|
||||
return
|
||||
}
|
||||
var (
|
||||
@@ -145,17 +146,17 @@ func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
token, exists = context.Query(TOKEN)
|
||||
if !exists {
|
||||
httpError(context, constant.ErrConnArgsErr)
|
||||
httpError(context, errs.ErrConnArgsErr)
|
||||
return
|
||||
}
|
||||
userID, exists = context.Query(WS_USERID)
|
||||
if !exists {
|
||||
httpError(context, constant.ErrConnArgsErr)
|
||||
httpError(context, errs.ErrConnArgsErr)
|
||||
return
|
||||
}
|
||||
platformID, exists = context.Query(PLATFORM_ID)
|
||||
if !exists {
|
||||
httpError(context, constant.ErrConnArgsErr)
|
||||
httpError(context, errs.ErrConnArgsErr)
|
||||
return
|
||||
}
|
||||
err := tokenverify.WsVerifyToken(token, userID, platformID)
|
||||
|
||||
@@ -143,7 +143,7 @@ func (r *RPCServer) GetUsersOnlineStatus(_ context.Context, req *msggateway.GetU
|
||||
log.NewInfo(req.OperationID, "rpc GetUsersOnlineStatus arrived server", req.String())
|
||||
if !tokenverify.IsManagerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "no permission GetUsersOnlineStatus ", req.OpUserID)
|
||||
return &msggateway.GetUsersOnlineStatusResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
return &msggateway.GetUsersOnlineStatusResp{ErrCode: errs.ErrAccess.ErrCode, ErrMsg: errs.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
var resp msggateway.GetUsersOnlineStatusResp
|
||||
for _, userID := range req.UserIDList {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"OpenIM/pkg/common/log"
|
||||
"OpenIM/pkg/common/prome"
|
||||
"OpenIM/pkg/common/tokenverify"
|
||||
"OpenIM/pkg/errs"
|
||||
"OpenIM/pkg/proto/msggateway"
|
||||
"OpenIM/pkg/utils"
|
||||
"bytes"
|
||||
@@ -303,8 +304,8 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int, newConn
|
||||
func (ws *WServer) sendKickMsg(oldConn *UserConn) {
|
||||
mReply := Resp{
|
||||
ReqIdentifier: constant.WSKickOnlineMsg,
|
||||
ErrCode: constant.ErrTokenInvalid.ErrCode,
|
||||
ErrMsg: constant.ErrTokenInvalid.ErrMsg,
|
||||
ErrCode: int32(errs.ErrTokenInvalid.Code()),
|
||||
ErrMsg: errs.ErrTokenInvalid.Msg(),
|
||||
}
|
||||
var b bytes.Buffer
|
||||
enc := gob.NewEncoder(&b)
|
||||
@@ -443,47 +444,47 @@ 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 := tokenverify.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, errs.ErrTokenExpired) {
|
||||
status = int(errs.ErrTokenExpired.ErrCode)
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenInvalid) {
|
||||
status = int(constant.ErrTokenInvalid.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenInvalid) {
|
||||
status = int(errs.ErrTokenInvalid.ErrCode)
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenMalformed) {
|
||||
status = int(constant.ErrTokenMalformed.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenMalformed) {
|
||||
status = int(errs.ErrTokenMalformed.ErrCode)
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenNotValidYet) {
|
||||
status = int(constant.ErrTokenNotValidYet.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenNotValidYet) {
|
||||
status = int(errs.ErrTokenNotValidYet.ErrCode)
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenUnknown) {
|
||||
status = int(constant.ErrTokenUnknown.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenUnknown) {
|
||||
status = int(errs.ErrTokenUnknown.ErrCode)
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenKicked) {
|
||||
status = int(constant.ErrTokenKicked.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenKicked) {
|
||||
status = int(errs.ErrTokenKicked.ErrCode)
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenDifferentPlatformID) {
|
||||
status = int(constant.ErrTokenDifferentPlatformID.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenDifferentPlatformID) {
|
||||
status = int(errs.ErrTokenDifferentPlatformID.ErrCode)
|
||||
}
|
||||
if errors.Is(err, constant.ErrTokenDifferentUserID) {
|
||||
status = int(constant.ErrTokenDifferentUserID.ErrCode)
|
||||
if errors.Is(err, errs.ErrTokenDifferentUserID) {
|
||||
status = int(errs.ErrTokenDifferentUserID.ErrCode)
|
||||
}
|
||||
//switch errors.Cause(err) {
|
||||
//case constant.ErrTokenExpired:
|
||||
// status = int(constant.ErrTokenExpired.ErrCode)
|
||||
//case constant.ErrTokenInvalid:
|
||||
// status = int(constant.ErrTokenInvalid.ErrCode)
|
||||
//case constant.ErrTokenMalformed:
|
||||
// status = int(constant.ErrTokenMalformed.ErrCode)
|
||||
//case constant.ErrTokenNotValidYet:
|
||||
// status = int(constant.ErrTokenNotValidYet.ErrCode)
|
||||
//case constant.ErrTokenUnknown:
|
||||
// status = int(constant.ErrTokenUnknown.ErrCode)
|
||||
//case constant.ErrTokenKicked:
|
||||
// status = int(constant.ErrTokenKicked.ErrCode)
|
||||
//case constant.ErrTokenDifferentPlatformID:
|
||||
// status = int(constant.ErrTokenDifferentPlatformID.ErrCode)
|
||||
//case constant.ErrTokenDifferentUserID:
|
||||
// status = int(constant.ErrTokenDifferentUserID.ErrCode)
|
||||
//case errs.ErrTokenExpired:
|
||||
// status = int(errs.ErrTokenExpired.ErrCode)
|
||||
//case errs.ErrTokenInvalid:
|
||||
// status = int(errs.ErrTokenInvalid.ErrCode)
|
||||
//case errs.ErrTokenMalformed:
|
||||
// status = int(errs.ErrTokenMalformed.ErrCode)
|
||||
//case errs.ErrTokenNotValidYet:
|
||||
// status = int(errs.ErrTokenNotValidYet.ErrCode)
|
||||
//case errs.ErrTokenUnknown:
|
||||
// status = int(errs.ErrTokenUnknown.ErrCode)
|
||||
//case errs.ErrTokenKicked:
|
||||
// status = int(errs.ErrTokenKicked.ErrCode)
|
||||
//case errs.ErrTokenDifferentPlatformID:
|
||||
// status = int(errs.ErrTokenDifferentPlatformID.ErrCode)
|
||||
//case errs.ErrTokenDifferentUserID:
|
||||
// status = int(errs.ErrTokenDifferentUserID.ErrCode)
|
||||
//}
|
||||
|
||||
log.Error(operationID, "Token verify failed ", "query ", query, msg, err.Error(), "status: ", status)
|
||||
@@ -502,7 +503,7 @@ func (ws *WServer) headerCheck(w http.ResponseWriter, r *http.Request, operation
|
||||
return true, compression
|
||||
}
|
||||
} else {
|
||||
status = int(constant.ErrArgs.ErrCode)
|
||||
status = int(errs.ErrArgs.ErrCode)
|
||||
log.Error(operationID, "Args err ", "query ", query)
|
||||
w.Header().Set("Sec-Websocket-Version", "13")
|
||||
errMsg := "args err, need token, sendID, platformID"
|
||||
|
||||
Reference in New Issue
Block a user