Skip to content

Commit

Permalink
api/cannon: Stop retrying invalid webhooks forever (#2167)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed May 10, 2024
1 parent 21dbe39 commit e59ea27
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/api/src/webhooks/cannon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export default class WebhookCannon {
try {
ack = await this.processWebhookEvent(event);
} catch (err) {
ack = isRuntimeError(err);
// only ack the event if it's a runtime error (could lead to webhooks accumulating indefinitely) or an explicit
// unprocessable entity error, thrown for bad messages by processWebhookEvent.
ack = isRuntimeError(err) || err instanceof UnprocessableEntityError;
console.log("handleEventQueue Error ", err);
} finally {
if (ack) {
Expand All @@ -129,10 +131,6 @@ export default class WebhookCannon {
`Error handling recording.waiting event sessionId=${sessionId} err=`,
e
);
// only ack the event if it's an explicit unprocessable entity error
if (e instanceof UnprocessableEntityError) {
return true;
}
throw e;
}
}
Expand All @@ -154,7 +152,7 @@ export default class WebhookCannon {
});
if (!stream) {
// if stream isn't found. don't fire the webhook, log an error
throw new Error(
throw new UnprocessableEntityError(
`webhook Cannon: onTrigger: Stream Not found , streamId: ${streamId}`
);
}
Expand All @@ -166,10 +164,13 @@ export default class WebhookCannon {
}

let user = await db.user.get(userId);
if (!user || user.suspended) {
// if user isn't found. don't fire the webhook, log an error
throw new Error(
`webhook Cannon: onTrigger: User Not found , userId: ${userId}`
if (!user) {
throw new UnprocessableEntityError(
`webhook Cannon: onTrigger: User not found userId=${userId}`
);
} else if (user.suspended) {
throw new UnprocessableEntityError(
`webhook Cannon: onTrigger: User suspended userId=${userId}`
);
}

Expand Down Expand Up @@ -393,7 +394,7 @@ export default class WebhookCannon {
if (isSuccess(resp)) {
// 2xx requests are cool. all is good
logger.info(`webhook ${webhook.id} fired successfully`);
return true;
return;
}
if (resp.status >= 500) {
await this.retry(
Expand Down

0 comments on commit e59ea27

Please sign in to comment.