Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

860 B
Raw Blame
const TRANSIENT_ERRORS = new Set([
    'ProvisionedThroughputExceededException',
    'ThrottlingException',
    'RequestLimitExceeded',
    'InternalServerError',
    'ServiceUnavailableException',
    'TransactionConflictException',
    'KMSInternalException',
    'DependencyTimeoutException',
    'TimeoutError',
    'AbortError',
])
const TRANSIENT_ERROR_CODES = new Set(['ECONNRESET', 'ECONNREFUSED', 'EPIPE', 'ETIMEDOUT', 'EAI_AGAIN'])

export function isTransientError(error: unknown): boolean {
    if (!(error instanceof Error)) {
        return false
    }
    const { code, $retryable, $fault } = error as Error & { code?: string; $retryable?: unknown; $fault?: string }
    return (
        TRANSIENT_ERRORS.has(error.name) ||
        TRANSIENT_ERROR_CODES.has(code ?? '') ||
        $retryable !== undefined ||
        $fault === 'server'
    )
}