Tesla Timeout
A Timeout Middleware for Tesla Elixir HTTP Client
About
The timeout configuration may vary depending of the Tesla adapter being used (as well as its effects). To have an assertive and unified way of controlling timeout, we created this middleware that encapsulates the request on a GenServer with timeout. With this implementation we make sure that the timeout is always respected independent of the troubles the client may have.
Installation
def deps do
[
{:tesla_timeout, "~> 0.1.0"}
]
endUsage:
defmodule GoogleClient do
use Tesla
plug Tesla.Middleware.Timeout, :timer.seconds(2)
end
try do
GoogleClient.get("http://www.google.com:81/")
rescue e in Tesla.Error ->
IO.inspect(e)
end
# %Tesla.Error{
# message: "Elixir.Tesla.Middleware.Timeout: Request timeout.",
# reason: :timeout
# }