# `Lather.Error`
[🔗](https://github.com/awksedgreep/lather/blob/v1.0.49/lib/lather/error.ex#L1)

Comprehensive error handling for SOAP operations.

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

# `http_error`

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

# `lather_error`

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

# `soap_fault`

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

# `transport_error`

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

# `validation_error`

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

# `wsdl_error`

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

# `extract_debug_context`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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?`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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"})

---

*Consult [api-reference.md](api-reference.md) for complete listing*
