# `Mint.HTTPError`
[🔗](https://github.com/elixir-mint/mint/blob/v1.9.3/lib/mint/http_error.ex#L1)

An HTTP error.

This exception struct is used to represent HTTP errors of all sorts and for
both HTTP/1 and HTTP/2.

A `Mint.HTTPError` struct is an exception, so it can be raised as any
other exception.

## Struct

The `Mint.HTTPError` struct is opaque, that is, not all of its fields are public.
The list of public fields is:

  * `:reason` - the error reason. Can be one of:

    * a term of type `t:Mint.HTTP1.error_reason/0`. See its documentation for
      more information.

    * a term of type `t:Mint.HTTP2.error_reason/0`. See its documentation for
      more information.

    * `{:proxy, reason}`, which is used when an HTTP error happens when connecting
      to a tunnel proxy. `reason` can be:

      * `:tunnel_timeout` - when the tunnel times out.

      * `{:unexpected_status, status}` - when the proxy returns an unexpected
        status `status`.

      * `{:unexpected_trailing_responses, responses}` - when the proxy returns
        unexpected responses (`responses`).

## Message representation

If you want to convert an error reason to a human-friendly message (for example
for using in logs), you can use `Exception.message/1`:

    iex> {:error, %Mint.HTTPError{} = error} = Mint.HTTP.connect(:http, "bad-response.com", 80)
    iex> Exception.message(error)
    "the response contains two or more Content-Length headers"

# `proxy_reason`

```elixir
@type proxy_reason() ::
  {:proxy,
   Mint.HTTP1.error_reason()
   | Mint.HTTP2.error_reason()
   | :tunnel_timeout
   | {:unexpected_status, non_neg_integer()}
   | {:unexpected_trailing_responses, list()}}
```

# `reason`
*since 1.8.0* 

```elixir
@type reason() ::
  Mint.HTTP1.error_reason()
  | Mint.HTTP2.error_reason()
  | proxy_reason()
  | term()
```

The error reason.

# `t`

```elixir
@type t() :: %Mint.HTTPError{__exception__: term(), module: term(), reason: reason()}
```

Type for the `Mint.HTTPError` exception struct.

---

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