From 47a787ddee6e7bc4e0895a4d7798ec4d40783f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C3=B3jcikowski?= Date: Mon, 9 Dec 2024 12:21:49 +0000 Subject: [PATCH] Handle http errors from fetching remote files --- lib/waffle/file.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/waffle/file.ex b/lib/waffle/file.ex index 48d2e47..2a14a53 100644 --- a/lib/waffle/file.ex +++ b/lib/waffle/file.ex @@ -215,6 +215,21 @@ defmodule Waffle.File do {:ok, :retry} -> request(remote_path, headers, options, tries + 1) {:error, :out_of_tries} -> {:error, :recv_timeout} end + + {:ok, 503, _headers, client_ref} = response -> + case retry(tries, options) do + {:ok, :retry} -> + request(remote_path, headers, options, tries + 1) + + {:error, :out_of_tries} -> + :hackney.close(client_ref) + {:error, {:waffle_hackney_error, response}} + end + + {:ok, _, _, client_ref} = response -> + :hackney.close(client_ref) + {:error, {:waffle_hackney_error, response}} + _err -> {:error, :waffle_hackney_error}