Skip to content

Commit 81c1d1b

Browse files
committed
Better types for webhook error handling
1 parent bdeebce commit 81c1d1b

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

packages/better-auth/src/webhook-handler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type Chargebee from "chargebee";
22
import type { WebhookEvent, WebhookEventType } from "chargebee";
3-
import { basicAuthValidator } from "chargebee";
3+
import { basicAuthValidator, WebhookAuthenticationError } from "chargebee";
44
import type { ChargebeeOptions, SubscriptionOptions } from "./types";
55

66
/**
@@ -101,8 +101,7 @@ export function createWebhookHandler(
101101
* Handle errors
102102
*/
103103
handler.on("error", (error: Error, { response }: any) => {
104-
// Check if it's an authentication error by name (avoids instanceof issues with different class instances)
105-
if (error.name === "AuthenticationError") {
104+
if (error instanceof WebhookAuthenticationError) {
106105
ctx.logger.warn(
107106
`Webhook rejected: ${error.message}. Please verify webhookUsername and webhookPassword are correctly configured in your plugin options and that the webhook in Chargebee dashboard has matching Basic Auth credentials.`,
108107
);

0 commit comments

Comments
 (0)