Prompt

How do I debug a failing webhook on Cloudflare Workers?

Technology / Cloud Infrastructure1 observationLast seen Oct 26, 2026

Latest observation

Oct 26, 2026OpenAI APIWeb search: off

To debug a failing webhook on Cloudflare Workers, work through it in layers: request receipt, Worker logic, upstream/downstream call, and provider verification/retries.

1) Check whether the request reaches the Worker

  • In the Cloudflare dashboard, open your Worker and look at Logs / Tail Workers.
  • Use:
    wrangler tail
    
    This shows live logs, errors, and console.log() output.
  • Add a very early log:
    export default {
      async fetch(request, env, ctx) {
        console.log("Webhook hit", request.method, request.url);
        return new Response("ok");
      }
    }
    

If you don’t see logs, the webhook may not be reaching the route, DNS, or Worker binding.

2) Verify the route and HTTP method

Common issues:

  • Worker route doesn’t match the webhook URL
  • Provider sends POST, but your code only handles GET
  • Trailing slash or subdomain mismatch

Example:

if (request.method !== "POST") {
  return new Response("Method Not Allowed", { status: 405 });
}

3) Log headers and body safely

Many webhooks fail due to malformed JSON or signature checks.

export default {
  async fetch(request) {
    console.log("Headers:", Object.fromEntries(request.headers));

    const rawBody = await request.text();
    console.log("Raw body:", rawBody);

    try {
      const data = JSON.parse(rawBody);
      console.log("Parsed JSON:", data);
    } catch (err) {
      console.error("Invalid JSON:", err);
      return new Response("Bad Request", { status: 400 });
    }

    return new Response("ok");
  }
}

Notes:

  • Use request.text() first if you need the raw payload for signature verification.
  • Don’t call request.json() first if you also need the raw body; the body can only be consumed once.

4) Check signature verification

If your webhook provider signs requests, failures often come from:

  • wrong secret
  • using parsed JSON instead of raw body
  • header name mismatch
  • clock skew for timestamp-based signatures
  • different canonicalization rules

Pattern:

const rawBody = await request.text();
const signature = request.headers.get("x-signature");

Be sure to match the provider’s exact verification algorithm.

5) Inspect runtime errors

Use try/catch around your main logic:

try {
  // webhook logic
} catch (err) {
  console.error("Webhook handler failed:", err);
  return new Response("Internal Error", { status: 500 });
}

In wrangler tail, look for:

  • stack traces
  • uncaught promise rejections
  • serialization errors
  • TypeError: Body has already been used

6) Test locally

Run:

wrangler dev

Then send a test request:

curl -X POST http://127.0.0.1:8787/ \
  -H "Content-Type: application/json" \
  -d '{"hello":"world"}'

For signature-based webhooks, test with the exact provider payload if possible.

7) Return the right response quickly

Most webhook providers expect a fast 2xx response. If your Worker does slow work:

  • acknowledge immediately
  • use ctx.waitUntil() for async follow-up work
export default {
  async fetch(request, env, ctx) {
    ctx.waitUntil(doAsyncWork());
    return new Response("ok", { status: 200 });
  }
}

8) Check external calls from the Worker

If your webhook forwards data to another service:

  • log the upstream response status/body
  • confirm outbound fetch works
  • watch for CORS confusion (usually not relevant server-to-server)
  • confirm env vars and secrets are set correctly
const res = await fetch("https://example.com/api", { method: "POST", body: rawBody });
console.log("Upstream status:", res.status);
console.log("Upstream response:", await res.text());

9) Use structured logs

Prefer logs like:

console.log(JSON.stringify({
  event: "webhook_received",
  requestId: crypto.randomUUID(),
  method: request.method
}));

This makes searching much easier in wrangler tail or dashboard logs.

10) Common Cloudflare-specific gotchas

  • Route not deployed or wrong environment
  • Worker subrequest limits if it makes many fetches
  • CPU time limits causing timeouts
  • waitUntil not used for background work
  • Secrets not present in the environment:
    wrangler secret put WEBHOOK_SECRET
    
  • Different staging vs production URL in the webhook provider

Minimal debugging template

export default {
  async fetch(request, env, ctx) {
    console.log("Incoming webhook:", request.method, request.url);

    try {
      const raw = await request.text();
      console.log("Raw body:", raw);

      // verify signature here using raw body

      ctx.waitUntil((async () => {
        // background processing
      })());

      return new Response("ok", { status: 200 });
    } catch (err) {
      console.error("Webhook error:", err);
      return new Response("error", { status: 500 });
    }
  }
}

If you want, I can also give you:

  1. a step-by-step checklist for debugging a specific provider like Stripe/GitHub/Slack, or
  2. a signature verification example for Workers.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.