| 254 | } |
| 255 | |
| 256 | func wshandleError(ws *websocket.Conn, err error) bool { |
| 257 | if err != nil { |
| 258 | global.LOG.Errorf("handler ws faled:, err: %v", err) |
| 259 | dt := time.Now().Add(time.Second) |
| 260 | if ctlerr := ws.WriteControl(websocket.CloseMessage, []byte(err.Error()), dt); ctlerr != nil { |
| 261 | wsData, marshalErr := json.Marshal(terminal.WsMsg{ |
| 262 | Type: terminal.WsMsgCmd, |
| 263 | Data: base64.StdEncoding.EncodeToString([]byte(err.Error())), |
| 264 | }) |
| 265 | if marshalErr != nil { |
| 266 | _ = ws.WriteMessage(websocket.TextMessage, []byte("{\"type\":\"cmd\",\"data\":\"failed to encoding to json\"}")) |
| 267 | } else { |
| 268 | _ = ws.WriteMessage(websocket.TextMessage, wsData) |
| 269 | } |
| 270 | } |
| 271 | return true |
| 272 | } |
| 273 | return false |
| 274 | } |