From ef74cdca0b6bcc9d28c150ada21514cad149b9d1 Mon Sep 17 00:00:00 2001 From: Guillaume Hivert Date: Tue, 21 May 2024 20:16:57 +0200 Subject: [PATCH] fix: retry get_tarball on error Signed-off-by: Guillaume Hivert --- apps/backend/src/api/hex_repo.gleam | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/backend/src/api/hex_repo.gleam b/apps/backend/src/api/hex_repo.gleam index 502a319..a3b3b7b 100644 --- a/apps/backend/src/api/hex_repo.gleam +++ b/apps/backend/src/api/hex_repo.gleam @@ -1,5 +1,6 @@ import backend/error import gleam/bit_array +import gleam/erlang/process import gleam/http import gleam/http/request import gleam/httpc @@ -89,8 +90,14 @@ fn get_tarball(name: String, version: String) { |> request.set_scheme(http.Https) |> httpc.send_bits() |> result.map_error(error.FetchError) - |> result.map(fn(res) { - create_archive(archives_path, name, version, res.body) + |> result.try(fn(res) { + case res.status { + 200 -> Ok(create_archive(archives_path, name, version, res.body)) + _ -> { + process.sleep(1000) + get_tarball(name, version) + } + } }) }