{"record":{"id":"c0fac7197cb45aed","repo":"AlexxIT/go2rtc","slug":"wrong-status-res-status","errorCode":null,"errorMessage":"wrong status: ${res.Status}","messagePattern":"wrong status: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tcp/websocket/dial.go","lineNumber":44,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tkey, accept := GetKeyAccept()\n\n\t// Version, Key, Protocol important for Axis cameras\n\treq.Header.Set(\"Connection\", \"Upgrade\")\n\treq.Header.Set(\"Upgrade\", \"websocket\")\n\treq.Header.Set(\"Sec-WebSocket-Version\", \"13\")\n\treq.Header.Set(\"Sec-WebSocket-Key\", key)\n\treq.Header.Set(\"Sec-WebSocket-Protocol\", \"binary\")\n\n\tres, err := tcp.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif res.StatusCode != http.StatusSwitchingProtocols {\n\t\treturn nil, errors.New(\"wrong status: \" + res.Status)\n\t}\n\n\tif res.Header.Get(\"Sec-Websocket-Accept\") != accept {\n\t\treturn nil, errors.New(\"wrong websocket accept\")\n\t}\n\n\treturn NewClient(*pconn), nil\n}\n\nfunc GetKeyAccept() (key, accept string) {\n\tb := make([]byte, 16)\n\t_, _ = cryptorand.Read(b)\n\tkey = base64.StdEncoding.EncodeToString(b)\n\n\th := sha1.New()\n\th.Write([]byte(key))\n\th.Write([]byte(\"258EAFA5-E914-47DA-95CA-C5AB0DC85B11\"))\n\taccept = base64.StdEncoding.EncodeToString(h.Sum(nil))","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tcp/websocket/dial.go#L26-L62","documentation":"WebSocket Dial upgrade guard: the server's response to the upgrade request is not 101 Switching Protocols (res.Status appended). The endpoint did not accept the WebSocket handshake — often auth failure (401), wrong path (404), or a plain HTTP responder.","triggerScenarios":"Thrown at pkg/tcp/websocket/dial.go:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the appended status: 401 -> credentials needed, 404 -> wrong WebSocket path","Confirm the URL points at a WebSocket endpoint, not plain HTTP","Ensure required headers (Authorization, subprotocol) are provided"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}