Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed Dec 9, 2024
1 parent 0ef04b2 commit b62cca1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions protocol/streaming/ws/websocket_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,29 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) {
clobPairIds, err := parseUint32(r, CLOB_PAIR_IDS_QUERY_PARAM)
if err != nil {
ws.logger.Error("Error parsing clobPairIds", "err", err)
sendCloseWithReason(conn, websocket.CloseUnsupportedData, err.Error())
if err := sendCloseWithReason(conn, websocket.CloseUnsupportedData, err.Error()); err != nil {
ws.logger.Error("Error sending close message", "err", err)
}
return
}

// Parse marketIds from query parameters
marketIds, err := parseUint32(r, MARKET_IDS_QUERY_PARAM)
if err != nil {
ws.logger.Error("Error parsing marketIds", "err", err)
sendCloseWithReason(conn, websocket.CloseUnsupportedData, err.Error())
if err := sendCloseWithReason(conn, websocket.CloseUnsupportedData, err.Error()); err != nil {
ws.logger.Error("Error sending close message", "err", err)
}
return
}

// Parse subaccountIds from query parameters
subaccountIds, err := parseSubaccountIds(r)
if err != nil {
ws.logger.Error("Error parsing subaccountIds", "err", err)
sendCloseWithReason(conn, websocket.CloseUnsupportedData, err.Error())
if err := sendCloseWithReason(conn, websocket.CloseUnsupportedData, err.Error()); err != nil {
ws.logger.Error("Error sending close message", "err", err)
}
return
}

Expand All @@ -111,15 +117,19 @@ func (ws *WebsocketServer) Handler(w http.ResponseWriter, r *http.Request) {
"Ending handler for websocket connection",
"err", err,
)
sendCloseWithReason(conn, websocket.CloseInternalServerErr, err.Error())
if err := sendCloseWithReason(conn, websocket.CloseInternalServerErr, err.Error()); err != nil {
ws.logger.Error("Error sending close message", "err", err)
}
return
}
}

func sendCloseWithReason(conn *websocket.Conn, closeCode int, reason string) error {
closeMessage := websocket.FormatCloseMessage(closeCode, reason)
// Set a write deadline to avoid blocking indefinitely
conn.SetWriteDeadline(time.Now().Add(CLOSE_DEADLINE))
if err := conn.SetWriteDeadline(time.Now().Add(CLOSE_DEADLINE)); err != nil {
return err
}
return conn.WriteControl(
websocket.CloseMessage,
closeMessage,
Expand Down

0 comments on commit b62cca1

Please sign in to comment.