Fivetrex.Error exception (Fivetrex v0.2.1)

View Source

Structured error types for Fivetran API responses.

All API functions in Fivetrex return {:error, %Fivetrex.Error{}} on failure. This struct provides structured information about what went wrong, making it easy to pattern match on error types and handle them appropriately.

Error Types

The :type field indicates the category of error:

  • :unauthorized - Invalid or missing API credentials (HTTP 401)
  • :not_found - The requested resource does not exist (HTTP 404)
  • :rate_limited - Too many requests; check :retry_after (HTTP 429)
  • :server_error - Fivetran server error (HTTP 5xx)
  • :unknown - Unexpected or unclassified error

Fields

  • :type - The error category (see above)
  • :message - Human-readable error message from Fivetran
  • :status - The HTTP status code (if applicable)
  • :retry_after - Seconds to wait before retrying (for :rate_limited errors)

Examples

Pattern matching on error types:

case Fivetrex.Connectors.get(client, "invalid_id") do
  {:ok, connector} ->
    # Handle success
    connector

  {:error, %Fivetrex.Error{type: :not_found}} ->
    # Resource doesn't exist
    nil

  {:error, %Fivetrex.Error{type: :unauthorized}} ->
    # Invalid credentials - re-authenticate
    raise "Invalid API credentials"

  {:error, %Fivetrex.Error{type: :rate_limited, retry_after: seconds}} ->
    # Wait and retry
    Process.sleep(seconds * 1000)
    Fivetrex.Connectors.get(client, "invalid_id")

  {:error, %Fivetrex.Error{type: :server_error, status: status}} ->
    # Log and maybe retry
    Logger.error("Fivetran server error: #{status}")
    {:error, :server_error}

  {:error, %Fivetrex.Error{message: message}} ->
    # Catch-all for other errors
    {:error, message}
end

Exception Behavior

Fivetrex.Error implements the Exception behaviour, so you can raise it:

{:error, error} = Fivetrex.Connectors.get(client, "invalid")
raise error
# => ** (Fivetrex.Error) Resource not found

Summary

Types

The category of error that occurred.

t()

A structured Fivetran API error.

Functions

Returns the error message for exception handling.

Types

error_type()

@type error_type() ::
  :unauthorized | :not_found | :rate_limited | :server_error | :unknown

The category of error that occurred.

  • :unauthorized - Authentication failed (401)
  • :not_found - Resource not found (404)
  • :rate_limited - Rate limit exceeded (429)
  • :server_error - Server-side error (5xx)
  • :unknown - Unexpected error

t()

@type t() :: %Fivetrex.Error{
  __exception__: true,
  message: String.t(),
  retry_after: integer() | nil,
  status: integer() | nil,
  type: error_type()
}

A structured Fivetran API error.

See module documentation for field descriptions and usage examples.

Functions

message(exception)

Returns the error message for exception handling.

This is called automatically when the error is raised.