Migrate to idiomatic error handling in app/websocket_router.go (#9708)

Этот коммит содержится в:
Hanzei
2018-10-18 18:04:43 +02:00
коммит произвёл George Goldberg
родитель d77e3a4c25
Коммит 0d87486e99

Просмотреть файл

@@ -50,10 +50,11 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
} }
session, err := wr.app.GetSession(token) session, err := wr.app.GetSession(token)
if err != nil { if err != nil {
conn.WebSocket.Close() conn.WebSocket.Close()
} else { return
}
wr.app.Go(func() { wr.app.Go(func() {
wr.app.SetStatusOnline(session.UserId, false) wr.app.SetStatusOnline(session.UserId, false)
wr.app.UpdateLastActivityAtIfNeeded(*session) wr.app.UpdateLastActivityAtIfNeeded(*session)
@@ -67,7 +68,6 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
resp := model.NewWebSocketResponse(model.STATUS_OK, r.Seq, nil) resp := model.NewWebSocketResponse(model.STATUS_OK, r.Seq, nil)
conn.Send <- resp conn.Send <- resp
}
return return
} }
@@ -78,13 +78,11 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque
return return
} }
var handler webSocketHandler handler, ok := wr.handlers[r.Action]
if h, ok := wr.handlers[r.Action]; !ok { if !ok {
err := model.NewAppError("ServeWebSocket", "api.web_socket_router.bad_action.app_error", nil, "", http.StatusInternalServerError) err := model.NewAppError("ServeWebSocket", "api.web_socket_router.bad_action.app_error", nil, "", http.StatusInternalServerError)
ReturnWebSocketError(conn, r, err) ReturnWebSocketError(conn, r, err)
return return
} else {
handler = h
} }
handler.ServeWebSocket(conn, r) handler.ServeWebSocket(conn, r)