Skip to content

Commit bb1839a

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

2 files changed

Lines changed: 3 additions & 4 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
);

packages/better-auth/tsdown.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from "tsdown";
33
export default defineConfig({
44
dts: { build: true, incremental: true },
55
format: ["esm"],
6-
entry: ["./src/index.ts"],
6+
entry: ["./src/index.ts", "./src/client.ts"],
77
external: ["better-auth", "better-call", "@better-fetch/fetch", "chargebee"],
88
sourcemap: true,
99
});

0 commit comments

Comments
 (0)