mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-06 21:32:15 +08:00
refactor: separate functions with error containing message and error with only stack trace.
This commit is contained in:
parent
1c29734a76
commit
1ebd4aa0d9
@ -16,6 +16,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -52,8 +53,8 @@ import (
|
|||||||
|
|
||||||
func Start(config *config.GlobalConfig, port int, proPort int) error {
|
func Start(config *config.GlobalConfig, port int, proPort int) error {
|
||||||
if port == 0 || proPort == 0 {
|
if port == 0 || proPort == 0 {
|
||||||
err := "port or proPort is empty:" + strconv.Itoa(port) + "," + strconv.Itoa(proPort)
|
err := errors.New("port or proPort is empty:" + strconv.Itoa(port) + "," + strconv.Itoa(proPort))
|
||||||
return errs.Wrap(fmt.Errorf(err))
|
return errs.Wrap(err)
|
||||||
}
|
}
|
||||||
rdb, err := cache.NewRedis(&config.Redis)
|
rdb, err := cache.NewRedis(&config.Redis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -85,7 +86,7 @@ func Start(config *config.GlobalConfig, port int, proPort int) error {
|
|||||||
p := ginprom.NewPrometheus("app", prommetrics.GetGinCusMetrics("Api"))
|
p := ginprom.NewPrometheus("app", prommetrics.GetGinCusMetrics("Api"))
|
||||||
p.SetListenAddress(fmt.Sprintf(":%d", proPort))
|
p.SetListenAddress(fmt.Sprintf(":%d", proPort))
|
||||||
if err = p.Use(router); err != nil && err != http.ErrServerClosed {
|
if err = p.Use(router); err != nil && err != http.ErrServerClosed {
|
||||||
netErr = errs.Wrap(err, fmt.Sprintf("prometheus start err: %d", proPort))
|
netErr = errs.WrapMsg(err, fmt.Sprintf("prometheus start err: %d", proPort))
|
||||||
netDone <- struct{}{}
|
netDone <- struct{}{}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -104,7 +105,7 @@ func Start(config *config.GlobalConfig, port int, proPort int) error {
|
|||||||
go func() {
|
go func() {
|
||||||
err = server.ListenAndServe()
|
err = server.ListenAndServe()
|
||||||
if err != nil && err != http.ErrServerClosed {
|
if err != nil && err != http.ErrServerClosed {
|
||||||
netErr = errs.Wrap(err, fmt.Sprintf("api start err: %s", server.Addr))
|
netErr = errs.WrapMsg(err, fmt.Sprintf("api start err: %s", server.Addr))
|
||||||
netDone <- struct{}{}
|
netDone <- struct{}{}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -188,7 +188,7 @@ func (c *Client) handleMessage(message []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if binaryReq.SendID != c.UserID {
|
if binaryReq.SendID != c.UserID {
|
||||||
return errs.Wrap(errors.New("exception conn userID not same to req userID"), binaryReq.String())
|
return errs.WrapMsg(errors.New("exception conn userID not same to req userID"), binaryReq.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := mcontext.WithMustInfoCtx(
|
ctx := mcontext.WithMustInfoCtx(
|
||||||
|
|||||||
@ -209,7 +209,7 @@ func (ws *WsServer) Run(done chan error) error {
|
|||||||
case err = <-done:
|
case err = <-done:
|
||||||
sErr := server.Shutdown(ctx)
|
sErr := server.Shutdown(ctx)
|
||||||
if sErr != nil {
|
if sErr != nil {
|
||||||
return errs.Wrap(sErr, "shutdown err")
|
return errs.WrapMsg(sErr, "shutdown err")
|
||||||
}
|
}
|
||||||
close(shutdownDone)
|
close(shutdownDone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -463,7 +463,7 @@ func (ws *WsServer) ParseWSArgs(r *http.Request) (args *WSArgs, err error) {
|
|||||||
case constant.KickedToken:
|
case constant.KickedToken:
|
||||||
return nil, errs.ErrTokenKicked.Wrap()
|
return nil, errs.ErrTokenKicked.Wrap()
|
||||||
default:
|
default:
|
||||||
return nil, errs.ErrTokenUnknown.Wrap(fmt.Sprintf("token status is %d", v))
|
return nil, errs.ErrTokenUnknown.WrapMsg(fmt.Sprintf("token status is %d", v))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errs.ErrTokenNotExist.Wrap()
|
return nil, errs.ErrTokenNotExist.Wrap()
|
||||||
|
|||||||
@ -138,7 +138,7 @@ func (m *MsgTransfer) Start(prometheusPort int, config *config.GlobalConfig) err
|
|||||||
http.Handle("/metrics", promhttp.HandlerFor(proreg, promhttp.HandlerOpts{Registry: proreg}))
|
http.Handle("/metrics", promhttp.HandlerFor(proreg, promhttp.HandlerOpts{Registry: proreg}))
|
||||||
err := http.ListenAndServe(fmt.Sprintf(":%d", prometheusPort), nil)
|
err := http.ListenAndServe(fmt.Sprintf(":%d", prometheusPort), nil)
|
||||||
if err != nil && err != http.ErrServerClosed {
|
if err != nil && err != http.ErrServerClosed {
|
||||||
netErr = errs.Wrap(err, fmt.Sprintf("prometheus start err: %d", prometheusPort))
|
netErr = errs.WrapMsg(err, fmt.Sprintf("prometheus start err: %d", prometheusPort))
|
||||||
netDone <- struct{}{}
|
netDone <- struct{}{}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user