{"record":{"id":"f67f53d4239eeb2a","repo":"chenhg5/cc-connect","slug":"gateway-request-failed-w","errorCode":null,"errorMessage":"gateway request failed: %w","messagePattern":"gateway request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/qqbot/qqbot.go","lineNumber":694,"sourceCode":"\t// so we can cancel them cleanly on reconnect.\n\tconnCtx, connCancel := context.WithCancel(ctx)\n\tp.connCancel = connCancel\n\tgo p.heartbeatLoop(connCtx)\n\tgo p.readLoop(connCtx)\n\n\treturn nil\n}\n\nfunc (p *Platform) getGatewayURL(token string) (string, error) {\n\treq, err := http.NewRequest(\"GET\", p.apiBase()+\"/gateway/bot\", nil)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treq.Header.Set(\"Authorization\", \"QQBot \"+token)\n\n\tresp, err := core.HTTPClient.Do(req)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"gateway request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tvar result struct {\n\t\tURL string `json:\"url\"`\n\t}\n\tif err := json.NewDecoder(resp.Body).Decode(&result); err != nil {\n\t\treturn \"\", fmt.Errorf(\"gateway response decode: %w\", err)\n\t}\n\tif result.URL == \"\" {\n\t\treturn \"\", fmt.Errorf(\"empty gateway URL in response\")\n\t}\n\treturn result.URL, nil\n}\n\ntype wsPayload struct {\n\tOp int             `json:\"op\"`\n\tD  json.RawMessage `json:\"d,omitempty\"`","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/qqbot/qqbot.go#L676-L712","documentation":"Returned by the gateway URL fetch when the HTTP request to the QQ gateway endpoint (Authorization: QQBot <token>) fails at the transport level — connection error, timeout, or request construction failure. No gateway URL can be obtained, so the WS connection cannot proceed.","triggerScenarios":"core.HTTPClient.Do(req) returns an error when fetching the gateway URL: DNS failure, refused connection, TLS error, or client timeout.","commonSituations":"Machine without internet access; QQ API endpoint temporarily down; an aggressive timeout in core.HTTPClient; wrong apiBase pointing to a nonexistent host in a test environment.","solutions":["Check network connectivity to the QQ open-platform API host from the host machine","Verify the configured apiBase is the correct QQ API base URL","Increase the HTTP client timeout if it is too tight","Retry with exponential backoff; wrap so the app can reconnect later"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if core.HTTPClient == nil || core.HTTPClient.Timeout == 0 {\n    core.HTTPClient = &http.Client{Timeout: 15 * time.Second}\n}","typeGuard":null,"tryCatchPattern":"resp, err := core.HTTPClient.Do(req)\nif err != nil {\n    slog.Warn(\"gateway fetch failed, will retry\", \"err\", err)\n    time.Sleep(2 * time.Second)\n    return getGatewayURL() // bounded retries\n}","preventionTips":["Verify DNS/proxy config on the host before deployment","Keep an HTTP client with sane timeouts","Alert on repeated transport failures to QQ APIs"],"tags":["http","network","qqbot","gateway"],"backgroundTag":"api-request-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}