Skip to content

Commit 7760552

Browse files
committed
Update webhook errors location
1 parent c687157 commit 7760552

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

template/app/src/payment/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class UnhandledWebhookEventError extends Error {
2+
constructor(eventType: string) {
3+
super(`Unhandled event type: ${eventType}`);
4+
this.name = 'UnhandledWebhookEventError';
5+
}
6+
}

template/app/src/payment/lemonSqueezy/webhook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import crypto from 'crypto';
99
import { requireNodeEnvVar } from '../../server/utils';
1010
import { parseWebhookPayload, type OrderData, type SubscriptionData } from './webhookPayload';
1111
import { assertUnreachable } from '../../shared/utils';
12-
import { UnhandledWebhookEvent } from '../webhook';
12+
import { UnhandledWebhookEventError } from '../errors';
1313

1414
export const lemonSqueezyWebhook: PaymentsWebhook = async (request, response, context) => {
1515
try {
@@ -28,7 +28,7 @@ export const lemonSqueezyWebhook: PaymentsWebhook = async (request, response, co
2828
}
2929

3030
const payload = await parseWebhookPayload(rawBody).catch((e) => {
31-
if (e instanceof UnhandledWebhookEvent) {
31+
if (e instanceof UnhandledWebhookEventError) {
3232
throw new HttpError(500, e.message);
3333
} else {
3434
console.error('Error parsing webhook payload', e);

template/app/src/payment/lemonSqueezy/webhookPayload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as z from 'zod';
2-
import { UnhandledWebhookEvent } from '../webhook';
2+
import { UnhandledWebhookEventError } from '../errors';
33

44
export async function parseWebhookPayload(rawPayload: string) {
55
const rawEvent = JSON.parse(rawPayload) as unknown;
@@ -25,7 +25,7 @@ export async function parseWebhookPayload(rawPayload: string) {
2525
return { eventName: event.meta.event_name, meta: event.meta, data: subscriptionData };
2626
default:
2727
// If you'd like to handle more events, you can add more cases above.
28-
throw new UnhandledWebhookEvent(event.meta.event_name);
28+
throw new UnhandledWebhookEventError(event.meta.event_name);
2929
}
3030
}
3131

template/app/src/payment/stripe/webhook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
SubscriptionDeletedData,
1818
SubscriptionUpdatedData,
1919
} from './webhookPayload';
20-
import { UnhandledWebhookEvent } from '../webhook';
20+
import { UnhandledWebhookEventError } from '../errors';
2121

2222
export const stripeWebhook: PaymentsWebhook = async (request, response, context) => {
2323
const secret = requireNodeEnvVar('STRIPE_WEBHOOK_SECRET');
@@ -27,7 +27,7 @@ export const stripeWebhook: PaymentsWebhook = async (request, response, context)
2727
}
2828
const rawStripeEvent = ensureStripeEvent(request, sig, secret);
2929
const payload = await parseWebhookPayload(rawStripeEvent).catch((e) => {
30-
if (e instanceof UnhandledWebhookEvent) {
30+
if (e instanceof UnhandledWebhookEventError) {
3131
throw new HttpError(500, e.message);
3232
} else {
3333
console.error('Error parsing webhook payload', e);

template/app/src/payment/stripe/webhookPayload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as z from 'zod';
22
import { Stripe } from 'stripe';
3-
import { UnhandledWebhookEvent } from '../webhook';
3+
import { UnhandledWebhookEventError } from '../errors';
44

55
export async function parseWebhookPayload(rawStripeEvent: Stripe.Event) {
66
const event = await genericStripeEventSchema.parseAsync(rawStripeEvent).catch((e) => {
@@ -38,7 +38,7 @@ export async function parseWebhookPayload(rawStripeEvent: Stripe.Event) {
3838
return { eventName: event.type, data: deletedSubscription };
3939
default:
4040
// If you'd like to handle more events, you can add more cases above.
41-
throw new UnhandledWebhookEvent(event.type);
41+
throw new UnhandledWebhookEventError(event.type);
4242
}
4343
}
4444

template/app/src/payment/webhook.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,3 @@ import { paymentProcessor } from './paymentProcessor';
22

33
export const paymentsWebhook = paymentProcessor.webhook;
44
export const paymentsMiddlewareConfigFn = paymentProcessor.webhookMiddlewareConfigFn;
5-
6-
export class UnhandledWebhookEvent extends Error {
7-
constructor(eventType: string) {
8-
super(`Unhandled event type: ${eventType}`);
9-
this.name = 'UnhandledWebhookEvent';
10-
}
11-
}

0 commit comments

Comments
 (0)