Skip to content

Commit c50bc44

Browse files
eabdelmoneimclaude
andauthored
fix: retry webhooks on 429 and 403 responses (#931)
Previously, only 5xx errors triggered webhook retries. This change adds 429 (Too Many Requests) and 403 (Forbidden) to the retry logic, treating them the same as server errors with exponential backoff. This prevents webhook events from being lost when the destination endpoint rate-limits requests or returns transient auth errors. Also fixes a pre-existing lint error (unused template literal). Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6cc8291 commit c50bc44

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/worker/tasks/send-webhook-worker.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const handler: Processor<string, void, string> = async (job: Job<string>) => {
8585
logger({
8686
service: "worker",
8787
level: "warn",
88-
message: `[Webhook] Transaction not found for webhook`,
88+
message: "[Webhook] Transaction not found for webhook",
8989
queueId: data.queueId,
9090
data: {
9191
eventType: data.type,
@@ -137,15 +137,21 @@ const handler: Processor<string, void, string> = async (job: Job<string>) => {
137137
});
138138
}
139139

140-
// Throw on 5xx so it remains in the queue to retry later.
141-
if (resp && resp.status >= 500) {
140+
// Throw on 5xx, 429 (rate limit), or 403 (forbidden) so it remains in the queue to retry later.
141+
if (resp && (resp.status >= 500 || resp.status === 429 || resp.status === 403)) {
142+
const errorType =
143+
resp.status === 429
144+
? "rate limited"
145+
: resp.status === 403
146+
? "forbidden"
147+
: "server error";
142148
const error = new Error(
143149
`Received status ${resp.status} from webhook ${webhook.url}.`,
144150
);
145151
job.log(error.message);
146152
logger({
147153
level: "error",
148-
message: `[Webhook] 5xx error, will retry`,
154+
message: `[Webhook] ${resp.status} ${errorType}, will retry`,
149155
service: "worker",
150156
queueId: transactionId,
151157
data: {

0 commit comments

Comments
 (0)