Hmbown/CodeWhale · error

webhook returned non-success status

Error message

webhook returned non-success status {}

What it means

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.

Solutions

  1. Check the returned status code in the error and fix the receiver-side cause (auth token, payload shape, rate limits)
  2. Verify the webhook endpoint URL and that the receiver is up and healthy
  3. Increase endpoint capacity or reduce event volume; retry later if the status was 5xx

Example fix

// before
emit(event, "https://old-endpoint.example/hook");
// after
// ensure receiver accepts POSTs with the current bearer token, e.g. 200 OK:
// curl -i -X POST -H "Authorization: Bearer $TOK" https://endpoint.example/hook
Defensive patterns

Strategy: retry

Validate before calling

// preflight: verify endpoint accepts the payload shape and auth
let resp = reqwest::Client::new()
    .post(url)
    .bearer_auth(token)
    .json(&probe_payload)
    .send()
    .await?;
if !resp.status().is_success() {
    eprintln!("webhook endpoint unhealthy: {}", resp.status());
}

Try / catch

if let Err(e) = hooks::post_payload(url, &payload).await {
    if e.to_string().contains("non-success status") {
        // inspect status, then retry later or route to a dead-letter log
        tracing::error!("webhook delivery failed: {e:#}");
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: Webhook receiver misconfigured or down; expired bearer token; payload schema mismatch on the receiver side; rate limiting during bursts of events.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/75380d973d840cc9. Report an issue: GitHub.

Appendix: source

Thrown at crates/hooks/src/lib.rs:255

    /// POST an arbitrary JSON payload to the configured endpoint.
    ///
    /// This is the shared delivery path behind both [`HookSink::emit`] and
    /// the lifecycle outbox fan-out. It is deliberately not part of the
    /// [`HookSink`] trait: outbox events are runtime event envelopes, not
    /// [`HookEvent`]s, and only the transport needs to be shared.
    pub async fn post_payload(&self, payload: serde_json::Value) -> Result<()> {
        let mut retries = 0usize;
        loop {
            let mut request = self.client.post(&self.url).json(&payload);
            if let Some(token) = self.bearer_token.as_deref().filter(|t| !t.is_empty()) {
                request = request.bearer_auth(token);
            }
            let resp = request.send().await;
            match resp {
                Ok(response) if response.status().is_success() => return Ok(()),
                Ok(response) => {
                    if retries >= 2 {
                        anyhow::bail!("webhook returned non-success status {}", response.status());
                    }
                }
                Err(err) => {
                    if retries >= 2 {
                        return Err(err).context("webhook request failed");
                    }
                }
            }
            retries += 1;
            tokio::time::sleep(std::time::Duration::from_millis(200 * retries as u64)).await;
        }
    }
}

#[async_trait]
impl HookSink for WebhookHookSink {
    async fn emit(&self, event: &HookEvent) -> Result<()> {
        self.post_payload(json!({

View on GitHub (pinned to 73e0f67d83)