Skip to Content

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, and replayMany.
  • 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 its maxEndpoints limit of endpoints. Thrown by endpoint create.
  • IDEMPOTENCY_CONFLICT: an accepted key identifies different event content. Thrown by publish.
  • REPLAY_IN_PROGRESS: an original delivery already has a pending or in-flight replay. Thrown by replay.
  • SCHEMA_MISMATCH: expected storage is missing or incompatible. Thrown by check() and Better Auth record reads.
  • SIGNATURE_INVALID: webhook headers or signature are invalid. Thrown by verifyWebhook and parseWebhook.
  • SIGNATURE_EXPIRED: webhook timestamp falls outside the configured tolerance. Thrown by verifyWebhook and parseWebhook.
  • PAYLOAD_INVALID: an authenticated webhook body fails envelope or receiver-payload validation. Thrown by parseWebhook.
  • TRANSACTION_REQUIRED: a supplied publication client has no active PostgreSQL transaction. Thrown by publish with options.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.

On this page