{"record":{"id":"e67b1744cfa2fcf1","repo":"chenhg5/cc-connect","slug":"http-d-s-e67b17","errorCode":null,"errorMessage":"HTTP %d: %s","messagePattern":"HTTP (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/max/max.go","lineNumber":355,"sourceCode":"\t}\n\tbody, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn err\n\t}\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, p.apiBase+\"/subscriptions\", bytes.NewReader(body))\n\tif err != nil {\n\t\treturn err\n\t}\n\tp.setAuth(req)\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode >= 300 {\n\t\trespBody, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))\n\t\treturn fmt.Errorf(\"HTTP %d: %s\", resp.StatusCode, respBody)\n\t}\n\treturn nil\n}\n\n// unsubscribe removes the webhook registration. Only used during Stop().\nfunc (p *Platform) unsubscribe(ctx context.Context, url string) error {\n\treq, err := http.NewRequestWithContext(ctx, http.MethodDelete, p.apiBase+\"/subscriptions\", nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\tp.setAuth(req)\n\tq := req.URL.Query()\n\tq.Set(\"url\", url)\n\treq.URL.RawQuery = q.Encode()\n\tresp, err := p.client.Do(req)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/max/max.go#L337-L373","documentation":"subscribe performs the webhook subscription HTTP request and returns this error when the MAX API responds with status >= 300. The message embeds the status code and up to 1KB of the response body for diagnosis.","triggerScenarios":"Any non-2xx response from the MAX subscribe endpoint: 400 for malformed URL, 401/403 for bad token or missing scopes, 5xx for server-side issues, hit during Start or the periodic resubscribeLoop.","commonSituations":"Expired bot token (401), webhook URL with disallowed scheme/host (400), MAX API outage (503), rate limiting (429) during aggressive resubscribes.","solutions":["Read the embedded status code and body: 401/403 → fix the bot token and its scopes.","400 → validate the webhook URL format and reachability requirements.","429/5xx → back off and let the resubscribe loop retry; do not hammer the endpoint.","Log respBody in your monitoring to catch API-side changes."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if !strings.HasPrefix(webhookURL, \"https://\") { return errors.New(\"webhook URL must be https\") }","typeGuard":null,"tryCatchPattern":"if err := p.Start(handler); err != nil {\n    var statusErr string\n    if strings.Contains(err.Error(), \"HTTP 401\") || strings.Contains(err.Error(), \"HTTP 403\") {\n        // do not retry: fix token first\n    } else if strings.Contains(err.Error(), \"HTTP 5\") {\n        // retry with exponential backoff\n    }\n    _ = statusErr\n}","preventionTips":["Distinguish 4xx (fix config/credentials) from 5xx/429 (retry with backoff)","Log the response body embedded in the error for API diagnostics","Keep the resubscribe interval moderate to avoid rate limits"],"tags":["go","http","webhook"],"backgroundTag":"http-error-response","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"}