The line that caused the problem had a comment above it explaining why it was correct.
} catch (error) {
// return 200 so Shopify doesn't retry and disable the endpoint
return new Response(null, { status: 200 })
}
I wrote that comment. I remember writing it. At the time it was a sensible engineering decision: webhook retries are noisy, a failing endpoint gets marked unhealthy, and I didn't want a transient database error to turn into a platform-level problem on a Tuesday afternoon.
What I did not think through is what "delivered" means to the sender. To Shopify, a 200 is not "I received your event". It is "I handled your event". Once it believes that, the event is finished. There is no retry, no dead-letter queue, no flag anywhere on my side, and — this is the part that took me a while — no error in any log, because from the perspective of every piece of code involved, nothing failed.
The endpoint returned 200. The system worked. Except the thing the event asked me to do never happened.
What the endpoints are actually for
Both of my Shopify apps implement the three mandatory GDPR webhooks. They are not optional and they are not decorative:
-
customers/data_request— a merchant's customer asked what data you hold about them. You must compile it and deliver it. -
customers/redact— that customer asked to be erased. You must actually erase, or irreversibly anonymise. -
shop/redact— the merchant uninstalled and 48 hours later asked you to delete the shop's data. You must delete it.
Two apps, three topics each, six handler paths. One of them compiles a bundle of conversation rows and emails it. One deletes messages and feedback and rewrites email and name into masked strings. One deletes the entire store record and everything hanging off it.
All six were wrapped in a try/catch that swallowed the failure and answered 200.
The audit that found it
I went through the compliance surface after reading about a regulator issuing a nine-figure fine over data handling. Not because I think a two-person Shopify app is the next target, but because "GDPR webhook" is one of those phrases that appears in every checklist and in almost no test suite.
So I did the obvious thing and started curling the endpoints.
Four tests per endpoint: no signature, a forged signature, a valid signature on a known topic, and a valid signature on a topic I don't implement. Six endpoints, twenty-four requests. The results were worse than the code review suggested:
| Test | App A | App B | Expected |
|---|---|---|---|
| No signature | 401 | 401 | 401 |
| Forged signature | 200 | 401 | 401 |
| Valid signature, known topic | 200 | 200 | 200 |
| Valid signature, unknown topic | 404 | 404 | 404 |
App B was accepting a forged HMAC and answering 200. That's a different bug with the same root cause — a catch that was written to be forgiving and ended up forgiving the wrong thing. The signature verification threw on mismatch, the catch turned the throw into success, and a request I should have rejected was recorded as handled.
The harness itself is about forty lines of Node: read the app secret, build a body that matches the topic's expected shape, sign it with crypto.createHmac('sha256', secret), post it with and without the header. The reason it took an afternoon rather than ten minutes is that a passing request and a swallowed exception return the same thing — 200, empty body, no distinguishing header. I ended up diffing response bodies against the handler's own log lines, because the status code was telling me nothing.
The bigger one is the one no test can see: with the catch in place, a handler that throws on a real database timeout returns 200 to Shopify, gets marked delivered, and never runs again. The deletion request is gone. The data stays. Nobody is notified — not me, not the merchant, not the customer who asked.
That's not a bug with a stack trace. That's a compliance failure with a green dashboard.
The fix, which is three lines and a lot of thinking
Three commits:
-
9cb2d7e6— App A: forged signature 200 → 401,catch200 → 500. -
7b9076bc— App B:catch200 → 500. -
a9ef59d9— unrelated but same audit: a disclosure line under the widget toggle in app settings, because the existing legal notice sat at the bottom of a long page and "you have to scroll to find out that conversations are stored" is not disclosure.
The status codes now mean what they mean:
if (!verifyHmac(rawBody, hmacHeader)) {
return new Response(null, { status: 401 }) // you are not Shopify
}
try {
await handle(topic, payload)
return new Response(null, { status: 200 }) // done, do not resend
} catch (error) {
await report(error) // tell me, in real time
return new Response(null, { status: 500 }) // not done, please resend
}
Re-verified online after deploy: forged signature 401 on both apps, valid signature 200 on shop/redact and customers/data_request, unknown topic 404. Same four test shapes, same six endpoints, all green — and this time green means something, because I had just watched red.
The tradeoff, stated plainly
Returning 500 is the correct thing to tell the sender and the expensive thing to own.
Once you return 500, three new obligations appear at once. Every handler must be idempotent, because retries are now real and a retried shop/redact will run twice. Your alerting has to actually work, because a 500 that nobody reads is just a slower version of the original bug. And your endpoint can now be judged unhealthy by the platform, which was the original fear and is still a real cost.
I took all three, because the alternative is a system that lies to its sender. Between "my endpoint might get flagged for retrying" and "a deletion request can vanish silently", the second one is not a tradeoff, it's a defect. The first one is an operational annoyance I can fix with a retry-safe handler and a log line.
The concrete work that came out of it: every handler now starts by checking whether it has already processed this event id, and redact is written so running it twice produces the same rows as running it once. That's maybe forty lines across both apps. The 200-in-catch saved me zero lines and cost me an unknown number of silently dropped deletions.
There's one more cost I should name, because it's the one that keeps me up: shop/redact arrives 48 hours after uninstall, and by then nobody is watching. The merchant is gone. There is no dashboard that shows "deletion pending". If that handler fails, the honest state of my system is "a shop's data still exists after the deadline the platform gave me", and nothing on any screen I own says so. A 500 at least produces a retry and an alert. The old 200 produced silence, which is the only failure mode that never gets fixed.
What I'd tell someone shipping their first Shopify app
The mandatory GDPR webhooks are the only endpoints in your app where the correct behaviour is invisible. A broken install flow produces a merchant complaint. A broken webhook produces nothing at all — the platform is satisfied, your logs are clean, and the only artefact is an obligation you didn't meet.
So test them the way you'd test a payment path: with a forged signature, with an unimplemented topic, and with a handler you deliberately make throw. That last one is the test that would have caught this, and it's the one nobody writes, because making your own code fail on purpose feels like breaking it.
If a handler of yours failed right now, what in your system would tell you — and would it tell you before or after the deadline in the request?
Top comments (3)
The forged-signature row is the scary one, and it comes from one try/catch doing two jobs. Splitting it fixes both bugs: verify the HMAC outside any catch and return 401 on mismatch, then for the handler either return a 5xx so Shopify retries, or write a "redact pending" row before answering 200 and alert when one is still open after a day. The redact topics suit the second option well, because you get a record that proves each deletion actually finished. Did you keep the 24-request curl harness as a CI test, so a future "forgiving" catch fails the build?
Shopify's own retries only run for about 48 hours, so even the honest 500 has a shelf life. If your endpoint is down when the uninstall deletion webhook lands and still down two days later, Shopify just gives up on it. fwiw the deliveries Shopify gave up on are why I built Webhook Relay. It keeps its own copy of every delivery, so you can replay long after the sender stopped trying.
The part that would still worry me is a crash after the signature check and before any row is written. I would record the obligation as soon as the webhook is accepted: the topic, the shop, and the deadline, before the handler runs. If the process dies mid-delete, that row is still open, and if the deadline passes with the data still there, it stays a failed obligation even after Shopify has stopped retrying.