Lather.Error (lather v1.0.42)

View Source

Comprehensive error handling for SOAP operations.

This module provides structured error types, SOAP fault parsing, and detailed error information for debugging SOAP service interactions.

Summary

Functions

Extracts error context for debugging.

Formats an error for display to users or logging.

Creates an HTTP error structure.

Parses SOAP fault from response body.

Checks if an error is recoverable (can be retried).

Creates a transport error structure.

Creates a validation error structure.

Creates a WSDL error structure.

Types

http_error()

@type http_error() :: %{
  type: :http_error,
  status: integer(),
  body: String.t(),
  headers: [{String.t(), String.t()}]
}

lather_error()

@type lather_error() ::
  soap_fault()
  | transport_error()
  | http_error()
  | wsdl_error()
  | validation_error()

soap_fault()

@type soap_fault() :: %{
  fault_code: String.t(),
  fault_string: String.t(),
  fault_actor: String.t() | nil,
  detail: map() | nil
}

transport_error()

@type transport_error() :: %{
  type: :transport_error,
  reason: atom() | String.t(),
  details: map()
}

validation_error()

@type validation_error() :: %{
  type: :validation_error,
  field: String.t(),
  reason: atom(),
  details: map()
}

wsdl_error()

@type wsdl_error() :: %{type: :wsdl_error, reason: atom(), details: map()}

Functions

extract_debug_context(error)

@spec extract_debug_context(lather_error()) :: map()

Extracts error context for debugging.

Parameters

  • error - The error to extract context from

Examples

context = Lather.Error.extract_debug_context(error)
# %{error_type: :soap_fault, timestamp: ~U[...], ...}

format_error(error, options \\ [])

@spec format_error(
  lather_error(),
  keyword()
) :: String.t() | map()

Formats an error for display to users or logging.

Parameters

  • error - The error structure to format
  • options - Formatting options

Options

  • :include_details - Whether to include detailed information (default: true)
  • :format - Format type (:string, :map, :json) (default: :string)

Examples

message = Lather.Error.format_error(error)
# "SOAP Fault: Server - Internal server error"

detailed = Lather.Error.format_error(error, include_details: true)

http_error(status, body, headers \\ [])

@spec http_error(integer(), String.t(), [{String.t(), String.t()}]) :: http_error()

Creates an HTTP error structure.

Parameters

  • status - HTTP status code
  • body - Response body
  • headers - Response headers

Examples

error = Lather.Error.http_error(500, "Internal Server Error", [])

parse_soap_fault(response_body, options \\ [])

@spec parse_soap_fault(
  String.t(),
  keyword()
) :: {:ok, soap_fault()} | {:error, term()}

Parses SOAP fault from response body.

Parameters

  • response_body - Raw XML response body containing SOAP fault
  • options - Parsing options

Examples

{:ok, fault} = Lather.Error.parse_soap_fault(response_body)
# %{
#   fault_code: "Server",
#   fault_string: "Internal server error",
#   fault_actor: nil,
#   detail: %{...}
# }

recoverable?(arg1)

@spec recoverable?(lather_error()) :: boolean()

Checks if an error is recoverable (can be retried).

Examples

true = Lather.Error.recoverable?(transport_error(:timeout, %{}))
false = Lather.Error.recoverable?(validation_error("field", :invalid_type, %{}))

transport_error(reason, details \\ %{})

@spec transport_error(atom() | String.t(), map()) :: transport_error()

Creates a transport error structure.

Parameters

  • reason - The transport error reason
  • details - Additional error details

Examples

error = Lather.Error.transport_error(:timeout, %{timeout_ms: 30000})

validation_error(field, reason, details \\ %{})

@spec validation_error(String.t(), atom(), map()) :: validation_error()

Creates a validation error structure.

Parameters

  • field - The field that failed validation
  • reason - The validation error reason
  • details - Additional error details

Examples

error = Lather.Error.validation_error("userId", :missing_required_field, %{})

wsdl_error(reason, details \\ %{})

@spec wsdl_error(atom(), map()) :: wsdl_error()

Creates a WSDL error structure.

Parameters

  • reason - The WSDL error reason
  • details - Additional error details

Examples

error = Lather.Error.wsdl_error(:invalid_wsdl, %{url: "http://example.com/wsdl"})