You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/msggateway/http_error.go

45 lines
1.1 KiB

2 years ago
package msggateway
import (
2 years ago
"OpenIM/pkg/errs"
"errors"
"net/http"
)
func httpError(ctx *UserConnContext, err error) {
code := http.StatusUnauthorized
ctx.SetHeader("Sec-Websocket-Version", "13")
ctx.SetHeader("ws_err_msg", err.Error())
2 years ago
if errors.Is(err, errs.ErrTokenExpired) {
code = errs.ErrTokenExpired.Code()
}
2 years ago
if errors.Is(err, errs.ErrTokenInvalid) {
code = errs.ErrTokenInvalid.Code()
}
2 years ago
if errors.Is(err, errs.ErrTokenMalformed) {
code = errs.ErrTokenMalformed.Code()
}
2 years ago
if errors.Is(err, errs.ErrTokenNotValidYet) {
code = errs.ErrTokenNotValidYet.Code()
}
2 years ago
if errors.Is(err, errs.ErrTokenUnknown) {
code = errs.ErrTokenUnknown.Code()
}
2 years ago
if errors.Is(err, errs.ErrTokenKicked) {
code = errs.ErrTokenKicked.Code()
}
2 years ago
if errors.Is(err, errs.ErrTokenDifferentPlatformID) {
code = errs.ErrTokenDifferentPlatformID.Code()
}
2 years ago
if errors.Is(err, errs.ErrTokenDifferentUserID) {
code = errs.ErrTokenDifferentUserID.Code()
}
2 years ago
if errors.Is(err, errs.ErrConnOverMaxNumLimit) {
code = errs.ErrConnOverMaxNumLimit.Code()
}
2 years ago
if errors.Is(err, errs.ErrConnArgsErr) {
code = errs.ErrConnArgsErr.Code()
}
ctx.ErrReturn(err.Error(), code)
}