Corsair
PluginsPostHog

PostHog Error Handlers

Built-in and custom error handling for PostHog

The PostHog plugin includes comprehensive error handling with built-in handlers for common error scenarios. You can also add custom error handlers to handle specific cases in your application.

New to Corsair? Learn about core concepts like error handling and retry strategies before customizing error handlers.

Full Implementation: For the complete, up-to-date error handler implementations, see the PostHog plugin source code on GitHub.

Built-in Error Handlers

The PostHog plugin automatically handles common error scenarios with sensible retry strategies.

Rate Limit Errors

Triggers: HTTP 429 status

Behavior:

  • Maximum retries: 5
  • Uses exponential backoff between retries

Authentication Errors

Triggers: HTTP 401 status, or error messages containing "Invalid API key"

Behavior:

  • Maximum retries: 0 (no retries)
  • Logs error to console
  • Fails immediately for manual intervention

Permission Errors

Triggers: HTTP 403 status

Behavior:

  • Maximum retries: 0 (no retries)
  • Logs warning to console
  • Fails immediately

Network Errors

Triggers: Network-related error messages

Behavior:

  • Maximum retries: 3
  • Uses exponential backoff
  • Logs warning to console

Default Error Handler

Triggers: Any error not matched by other handlers

Behavior:

  • Maximum retries: 0 (no retries)
  • Logs error to console
  • Fails immediately

Custom Error Handlers

You can add custom error handlers to handle specific scenarios:

corsair.ts
posthog({
    errorHandlers: {
        CUSTOM_ERROR: {
            match: (error, context) => {
                return error.message.includes("custom_error_code");
            },
            handler: async (error, context) => {
                return {
                    maxRetries: 2,
                };
            },
        },
    },
})

For comprehensive error handling strategies, patterns, and best practices, see the Error Handling concepts page.