{"record":{"id":"75380d973d840cc9","repo":"Hmbown/CodeWhale","slug":"webhook-returned-non-success-status","errorCode":null,"errorMessage":"webhook returned non-success status {}","messagePattern":"webhook returned non-success status (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/hooks/src/lib.rs","lineNumber":255,"sourceCode":"    /// POST an arbitrary JSON payload to the configured endpoint.\n    ///\n    /// This is the shared delivery path behind both [`HookSink::emit`] and\n    /// the lifecycle outbox fan-out. It is deliberately not part of the\n    /// [`HookSink`] trait: outbox events are runtime event envelopes, not\n    /// [`HookEvent`]s, and only the transport needs to be shared.\n    pub async fn post_payload(&self, payload: serde_json::Value) -> Result<()> {\n        let mut retries = 0usize;\n        loop {\n            let mut request = self.client.post(&self.url).json(&payload);\n            if let Some(token) = self.bearer_token.as_deref().filter(|t| !t.is_empty()) {\n                request = request.bearer_auth(token);\n            }\n            let resp = request.send().await;\n            match resp {\n                Ok(response) if response.status().is_success() => return Ok(()),\n                Ok(response) => {\n                    if retries >= 2 {\n                        anyhow::bail!(\"webhook returned non-success status {}\", response.status());\n                    }\n                }\n                Err(err) => {\n                    if retries >= 2 {\n                        return Err(err).context(\"webhook request failed\");\n                    }\n                }\n            }\n            retries += 1;\n            tokio::time::sleep(std::time::Duration::from_millis(200 * retries as u64)).await;\n        }\n    }\n}\n\n#[async_trait]\nimpl HookSink for WebhookHookSink {\n    async fn emit(&self, event: &HookEvent) -> Result<()> {\n        self.post_payload(json!({","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/hooks/src/lib.rs#L237-L273","documentation":"post_payload sends a webhook POST with retries (up to 3 attempts, retries >= 2 on the last); if the final response still has a non-2xx status, it fails with the returned status code. This surfaces the remote endpoint's rejection as an error instead of silently dropping the event.","triggerScenarios":"Emitting a hook event to a webhook URL that returns 4xx/5xx on all three attempts — bad auth (401/403), bad payload (400/422), rate limiting (429), or server errors (500/503).","commonSituations":"Webhook receiver misconfigured or down; expired bearer token; payload schema mismatch on the receiver side; rate limiting during bursts of events.","solutions":["Check the returned status code in the error and fix the receiver-side cause (auth token, payload shape, rate limits)","Verify the webhook endpoint URL and that the receiver is up and healthy","Increase endpoint capacity or reduce event volume; retry later if the status was 5xx"],"exampleFix":"// before\nemit(event, \"https://old-endpoint.example/hook\");\n// after\n// ensure receiver accepts POSTs with the current bearer token, e.g. 200 OK:\n// curl -i -X POST -H \"Authorization: Bearer $TOK\" https://endpoint.example/hook","handlingStrategy":"retry","validationCode":"// preflight: verify endpoint accepts the payload shape and auth\nlet resp = reqwest::Client::new()\n    .post(url)\n    .bearer_auth(token)\n    .json(&probe_payload)\n    .send()\n    .await?;\nif !resp.status().is_success() {\n    eprintln!(\"webhook endpoint unhealthy: {}\", resp.status());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = hooks::post_payload(url, &payload).await {\n    if e.to_string().contains(\"non-success status\") {\n        // inspect status, then retry later or route to a dead-letter log\n        tracing::error!(\"webhook delivery failed: {e:#}\");\n    }\n}","preventionTips":["Monitor webhook endpoint health (status, latency)","Rotate bearer tokens before expiry","Batch events to avoid 429 rate limiting"],"tags":["webhook","http","network"],"backgroundTag":"http-error-response","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}