Skip to content

Commit 8772ed3

Browse files
committed
Add exception handle for safe retry
1 parent 24be5b2 commit 8772ed3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/http_client/steps.ex

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,20 @@ defmodule HTTPClient.Steps do
403403
end
404404
end
405405

406-
defp retry_safe(request, response) do
406+
defp retry_safe(request, response_or_exception) do
407407
if request.method in [:get, :head] do
408-
case response do
408+
case response_or_exception do
409409
%Response{status: status} when status in [408, 429] or status in 500..599 ->
410-
retry(request, response)
410+
retry(request, response_or_exception)
411411

412412
%Response{} ->
413-
{request, response}
413+
{request, response_or_exception}
414+
415+
exception when is_exception(exception) ->
416+
retry(request, response_or_exception)
414417
end
415418
else
416-
{request, response}
419+
{request, response_or_exception}
417420
end
418421
end
419422

@@ -545,7 +548,7 @@ defmodule HTTPClient.Steps do
545548
end
546549

547550
case response_or_exception do
548-
%{__exception__: true} = exception ->
551+
exception when is_exception(exception) ->
549552
Logger.error(["retry: got exception. ", message])
550553
Logger.error(["** (#{inspect(exception.__struct__)}) ", Exception.message(exception)])
551554

0 commit comments

Comments
 (0)