Repository navigation
fix(content): don't mark an opportunity sent when its webhook redirects - #1590
Conversation
No redirect is followed since ansvisor#1568, so a 3xx means the payload never arrived. A single send answers 502 `webhook_redirect` ("The webhook address redirects. Use the address it redirects to."). A bulk send counts it failed. Either way the opportunity keeps its status, as Send to CMS does for a 3xx. Any other answer still marks it sent. The docs say so (api-reference/webhooks.mdx). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good, with follow-ups.
What I checked:
-
Own change. One commit on 5bbd162 (main):
isRedirectinsafe-post.js, the single and bulk opportunity sends incontent.js, both tests and one docs paragraph. It merges as is. -
The single send (
server/src/routes/content.js:1131-1137). A 3xx answers 502webhook_redirectbefore any write, so the row keeps its status and itswebhook_response. The web'ssendToWebhookhands the API'serrorto the toast, so the Opportunities list and the opportunity's page both say "The webhook address redirects. Use the address it redirects to." and leave the row as it was. Any other answer, a 4xx or 5xx too, still marks it sent, as before. -
The bulk send (
content.js:941-944). A 3xx counts failed and skips the write. The rows after it still go. -
Every sender that uses
postJsonnow reads a 3xx as not delivered:- opportunity, single: 502 and the redirect message (this PR);
- opportunity, bulk: counted failed (this PR);
- Daily Pulse (
dispatchBrandWebhook): only a 2xx counts, sowebhook_sentstays false; - Action Center task send: 502
webhook_failed, "The webhook didn't accept the task. Check its settings and try again."; - Send to CMS: the delivery fails, and the Library shows "The webhook answered 302";
- the Test button:
success: false, and the dialog shows "HTTP 302".
No open PR adds another
postJsoncaller. -
Docs.
webhooks.mdx:113matches the code, and Delivery (:296) already said a 3xx isn't followed. -
Tests. At the head, the route,
safe-post, dispatch, Send to CMS and task-send tests pass (72). With main'scontent.jsunder the PR's tests, the four 3xx cases and the bulk case fail (5 of 12). The mock now spreads the realsafe-post.js, so the routes use the realisRedirect. CI passes. -
Merge. #1507, #1573 and #1581 also edit
webhooks.mdx. Each still merges clean after this one, and the paragraph reads once. -
Speed. No new regex, and no new loop.
-
Before the API deploy. Server only, so nothing changes until the API is deployed. The API deploy that brings #1568 should bring this too.
-
#1568's other follow-ups. None is in this PR, as the description says: the cut-off 2xx (2), the test's messages (3), the test route's brand, role and limit (4), and the
User-Agentin the docs (5). Of these, 2 is the one a person meets: a task the webhook took can be reported as "didn't accept".
Follow-ups:
- A bulk send doesn't say why (
content.js:971,web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx:930-931).- A webhook that redirects does so for every row, so the person sees "Sent 0 opportunities to workflow" and "3 failed to send", with no reason.
- Count redirects on their own (
{ sent, failed, redirected }). When every failure was one, show the single send's message. - Show the success toast only when
sent > 0.
- The test's words for a redirect (
content.js:1214-1218,_webhook-settings.tsx:116).- The dialog shows "HTTP 302", where a send now says the address redirects.
- With
isRedirectexported, the test route can return the sameerrorfor a 3xx. It fits #1568's item 3 in the next PR.
…ebhook test, as a single send does (#1672) * fix(content): say a webhook redirects after a bulk send, and in the webhook test, as a single send does Follow-ups from #1590. A bulk send doesn't say why. A webhook that redirects does so for every row, so the person saw "Sent 0 opportunities to workflow" and "3 failed to send", with no reason. /bulk/send-webhook now counts the redirects on their own ({ sent, failed, redirected }). Opportunities shows the success note only when something was sent, and when every failure was a redirect, the single send's words: "Nothing was sent: the webhook address redirects. Use the address it redirects to." (bulkSendNotes, tested on its own; the page has no test of its own). "Sent 1 opportunities" reads "Sent 1 opportunity" now. The test's words for a redirect. The webhook test answers a 3xx with the same error a send gives (WEBHOOK_REDIRECT_ERROR), so the dialog says it for a redirect with no Location too, where it showed "HTTP 302". With a Location it still names the address to use. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(content): say "Nothing was sent" after a bulk send only when nothing was Review follow-up. - bulkSendNotes called it a redirect whenever every failure was one, so { sent: 1, failed: 1, redirected: 1 } showed both "Sent 1 opportunity" and "Nothing was sent: the webhook address redirects". It's the redirect note only when nothing was sent; otherwise "1 failed to send". - content.js: WEBHOOK_REDIRECT_ERROR sat between the imports; it's below them now. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Cihan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Follow-up 1 from #1568's approval, done first as asked, before any workspace sets a webhook up. A redirect no longer marks an opportunity Sent.
Since #1568,
postJsonfollows no redirect, so a webhook that answers 3xx never gets the payload. Until now the send still marked the opportunitysentand the toast said "Sent to workflow".POST /api/content/:id/send-webhook): a 3xx answers 502{ error: 'The webhook address redirects. Use the address it redirects to.', code: 'webhook_redirect', webhookStatus }.errorin the toast (sendToWebhookinlib/actions/content.ts), so no web change is needed.POST /api/content/bulk/send-webhook): a 3xx counts asfailed, before the write.sent, a 4xx or 5xx too. The "any answer marks sent" question stays where chore(server): post the other webhooks with postJson, as Send to CMS does (#1437 review) #1568 left it.isRedirect(status)sits inlib/safe-post.js, next to the rule it follows: no redirect is followed.api-reference/webhooks.mdx): a redirect counts as not delivered, and the opportunity keeps its status.Follow-ups 2–5 from the same approval go in their own PR:
User-Agentin the docs.Related issue
Follow-up to #1568 (item 1).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/routes/content-webhooks.test.js src/lib/safe-post.test.jswebhook_redirect, and nothing is written;http://URL that sends tohttps://), Send an opportunity:Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/) — no web changeyarn typecheckpasses (run fromweb/) — no web changeyarn format:checkpasses (run fromweb/) — no web changeAlso run, in
server/:npm run format,npm run lintandnpm test(2,947 tests pass).🤖 Generated with Claude Code