mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
ESLint 10's recommended set added preserve-caught-error: a catch block that
throws a new error has to pass the caught one as its cause. Five places
caught an error and threw a plainer one in its place — fetching the OIDC
configuration, sending a confirmation email, triggering a webhook,
validating a Zapier API token, rendering an email — and each failed the
lint.
Each now passes `{ cause: err }`. The thrown error keeps its message and
type; what it gains is the original, which Node prints after it as
`[cause]`. render-email-with-i18n.tsx also loses its stale ban-types
disable comment, as the five files in the commit before did.
Co-authored-by: Hanzo Dev <[email protected]>
38 lines
1005 B
TypeScript
38 lines
1005 B
TypeScript
import type { WebhookTriggerEvents } from '@prisma/client';
|
|
|
|
import { jobs } from '../../../jobs/client';
|
|
import { getAllWebhooksByEventTrigger } from '../get-all-webhooks-by-event-trigger';
|
|
|
|
export type TriggerWebhookOptions = {
|
|
event: WebhookTriggerEvents;
|
|
data: Record<string, unknown>;
|
|
userId: number;
|
|
teamId: number;
|
|
};
|
|
|
|
export const triggerWebhook = async ({ event, data, userId, teamId }: TriggerWebhookOptions) => {
|
|
try {
|
|
const registeredWebhooks = await getAllWebhooksByEventTrigger({ event, userId, teamId });
|
|
|
|
if (registeredWebhooks.length === 0) {
|
|
return;
|
|
}
|
|
|
|
await Promise.allSettled(
|
|
registeredWebhooks.map(async (webhook) => {
|
|
await jobs.triggerJob({
|
|
name: 'internal.execute-webhook',
|
|
payload: {
|
|
event,
|
|
webhookId: webhook.id,
|
|
data,
|
|
},
|
|
});
|
|
}),
|
|
);
|
|
} catch (err) {
|
|
console.error(err);
|
|
throw new Error(`Failed to trigger webhook`, { cause: err });
|
|
}
|
|
};
|