Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/tesla/middleware/retry.ex b/lib/tesla/middleware/retry.ex
index 507faa8..962009b 100644
--- a/lib/tesla/middleware/retry.ex
+++ b/lib/tesla/middleware/retry.ex
@@ -1,46 +1,46 @@
defmodule Tesla.Middleware.Retry do
@moduledoc """
Retry few times in case of connection refused error.
Example:
defmodule MyClient do
use Tesla
plug Tesla.Middleware.Retry, delay: 500, max_retries: 10
end
Options:
- - `:delay` - number of milisecond to wait before retrying (defaults to 1000)
+ - `:delay` - number of milliseconds to wait before retrying (defaults to 1000)
- `:max_retries` - maximum number of retries (defaults to 5)
"""
@defaults [
delay: 1000,
max_retries: 5
]
def call(env, next, opts) do
opts = opts || []
delay = Keyword.get(opts, :delay, @defaults[:delay])
max_retries = Keyword.get(opts, :max_retries, @defaults[:max_retries])
retry(env, next, delay, max_retries)
end
defp retry(env, next, _delay, retries) when retries <= 1 do
Tesla.run(env, next)
end
defp retry(env, next, delay, retries) do
Tesla.run(env, next)
rescue
error -> case error do
%Tesla.Error{} ->
:timer.sleep(delay)
retry(env, next, delay, retries - 1)
_ ->
reraise error, System.stacktrace
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 4:08 PM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
54761
Default Alt Text
(1 KB)

Event Timeline