Errors
Expected operation errors and failures recorded in delivery history.
Every expected failure throws a WebhookError with a stable code.
import { WebhookError } from 'good-webhooks'
import type { WebhookErrorCode } from 'good-webhooks'The receiver entry point good-webhooks/verify also exports the class and code type.
WebhookError
class WebhookError extends Error {
readonly name: 'WebhookError'
readonly code: WebhookErrorCode
constructor(code: WebhookErrorCode, message: string, options?: ErrorOptions)
}import { WebhookError } from 'good-webhooks'
import { webhooks } from './webhooks.js'
try {
await webhooks.publish({
type: 'invoice.paid',
data: { invoiceId: 'inv_123', amount: 4200 },
idempotencyKey: 'invoice.paid:inv_123',
})
} catch (error) {
if (error instanceof WebhookError && error.code === 'IDEMPOTENCY_CONFLICT') {
console.error('Idempotency key reused for a different payload:', error.message)
}
throw error
}WebhookError extends Error. It has name: 'WebhookError', a stable code, a descriptive message, and an optional cause.
Codes
INVALID_CONFIG: invalid constructor, encryption, migration, or receiver-validator configuration. Thrown by constructors,getPostgresMigration,parseWebhook,describeEvents, and secret decryption.INVALID_INPUT: invalid operation arguments or producer payload. Thrown by most operations.UNSAFE_URL: destination fails URL or resolved-address validation. Thrown by endpoint create, update, and resume.NOT_FOUND: record or owner is absent in the selected scope. Thrown by endpoint and delivery lookups, andreplayMany.INVALID_STATE: operation conflicts with lifecycle, limits, retention, or concurrent state. Thrown by endpoint lifecycle,replay,replayMany, and worker overlap.ENDPOINT_LIMIT: the scope already has itsmaxEndpointslimit of endpoints. Thrown by endpoint create.IDEMPOTENCY_CONFLICT: an accepted key identifies different event content. Thrown bypublish.REPLAY_IN_PROGRESS: an original delivery already has a pending or in-flight replay. Thrown byreplay.SCHEMA_MISMATCH: expected storage is missing or incompatible. Thrown bycheck()and Better Auth record reads.SIGNATURE_INVALID: webhook headers or signature are invalid. Thrown byverifyWebhookandparseWebhook.SIGNATURE_EXPIRED: webhook timestamp falls outside the configured tolerance. Thrown byverifyWebhookandparseWebhook.PAYLOAD_INVALID: an authenticated webhook body fails envelope or receiver-payload validation. Thrown byparseWebhook.TRANSACTION_REQUIRED: a supplied publication client has no active PostgreSQL transaction. Thrown bypublishwithoptions.transaction.
Each reference page lists the exact conditions for its operations.
describeEvents reports a target the validator rejects as INVALID_CONFIG naming the event, like any other conversion failure, because the validator's error cannot be told apart.
Failures outside WebhookError
Database errors, provider lookup failures, and unexpected validator failures can propagate as other error types. Code that handles WebhookError still needs a path for unexpected failures.
An HTTP recipient failure normally becomes a delivery and attempt record. It does not reject publish, because publication queues work without sending it. Worker internal failures can reject runOnce with an AggregateError. See retries and replay.
The Better Auth plugin maps expected management errors to HTTP responses. That mapping does not change the direct provider API.