Error Handling

Handle errors and exceptions in the Lightning Logs SDK.

Error Types

AuthenticationError

Thrown when authentication fails or token is invalid.

import { AuthenticationError } from '@lightning-logs/sdk'

try {
  await client.logs.search({ ... })
} catch (error) {
  if (error instanceof AuthenticationError) {
    // Handle authentication error
    console.error('Authentication failed:', error.message)
  }
}

ValidationError

Thrown when request parameters are invalid.

import { ValidationError } from '@lightning-logs/sdk'

try {
  await client.searches.create({ ... })
} catch (error) {
  if (error instanceof ValidationError) {
    console.error('Validation error:', error.message)
  }
}

FeatureNotAvailableError

Thrown when a feature is not available in the current plan.

import { FeatureNotAvailableError } from '@lightning-logs/sdk'

try {
  await client.searches.create({ ... })
} catch (error) {
  if (error instanceof FeatureNotAvailableError) {
    // Show upgrade prompt
    showUpgradePrompt()
  }
}

PlanLimitError

Thrown when a plan limit is exceeded.

import { PlanLimitError } from '@lightning-logs/sdk'

try {
  await client.searches.create({ ... })
} catch (error) {
  if (error instanceof PlanLimitError) {
    console.error('Plan limit reached:', error.message)
  }
}
Error Handling Pattern
import {
  SDKError,
  AuthenticationError,
  ValidationError,
  FeatureNotAvailableError,
  PlanLimitError
} from '@lightning-logs/sdk'

async function handleApiCall() {
  try {
    const result = await client.logs.search({
      tsFrom: '2025-01-15T00:00:00Z',
      tsTo: '2025-01-15T23:59:59Z',
      query: "level = 'error'"
    })
    return result
  } catch (error) {
    if (error instanceof AuthenticationError) {
      // Redirect to login
      redirectToLogin()
    } else if (error instanceof ValidationError) {
      // Show validation message
      showError(error.message)
    } else if (error instanceof FeatureNotAvailableError) {
      // Show upgrade prompt
      showUpgradePrompt()
    } else if (error instanceof PlanLimitError) {
      // Show limit reached message
      showLimitReached(error.message)
    } else if (error instanceof SDKError) {
      // Generic SDK error
      console.error('SDK Error:', error.message)
    } else {
      // Unknown error
      console.error('Unknown error:', error)
    }
    throw error
  }
}