Lather.Error (lather v1.0.42)
View SourceComprehensive 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
@type lather_error() :: soap_fault() | transport_error() | http_error() | wsdl_error() | validation_error()
Functions
@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[...], ...}
@spec format_error( lather_error(), keyword() ) :: String.t() | map()
Formats an error for display to users or logging.
Parameters
error- The error structure to formatoptions- 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)
@spec http_error(integer(), String.t(), [{String.t(), String.t()}]) :: http_error()
Creates an HTTP error structure.
Parameters
status- HTTP status codebody- Response bodyheaders- Response headers
Examples
error = Lather.Error.http_error(500, "Internal Server Error", [])
@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 faultoptions- Parsing options
Examples
{:ok, fault} = Lather.Error.parse_soap_fault(response_body)
# %{
# fault_code: "Server",
# fault_string: "Internal server error",
# fault_actor: nil,
# detail: %{...}
# }
@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, %{}))
@spec transport_error(atom() | String.t(), map()) :: transport_error()
Creates a transport error structure.
Parameters
reason- The transport error reasondetails- Additional error details
Examples
error = Lather.Error.transport_error(:timeout, %{timeout_ms: 30000})
@spec validation_error(String.t(), atom(), map()) :: validation_error()
Creates a validation error structure.
Parameters
field- The field that failed validationreason- The validation error reasondetails- Additional error details
Examples
error = Lather.Error.validation_error("userId", :missing_required_field, %{})
@spec wsdl_error(atom(), map()) :: wsdl_error()
Creates a WSDL error structure.
Parameters
reason- The WSDL error reasondetails- Additional error details
Examples
error = Lather.Error.wsdl_error(:invalid_wsdl, %{url: "http://example.com/wsdl"})