This commit is contained in:
silva guimaraes 2025-07-04 19:15:21 -03:00
parent a287461698
commit 4a66e35f8e
2 changed files with 7 additions and 4 deletions

View file

@ -156,6 +156,8 @@ end
let ( let* ) = Lwt.bind
exception Status_Not_found
(* TODO: handle "resolution fai led: name resolution failed" *)
let get url : string =
let http_get url =
@ -163,7 +165,8 @@ let get url : string =
Stdlib.flush Stdlib.stdout;
let* resp, body = Cohttp_lwt_unix.Client.get (Uri.of_string url) in
let code = resp |> Cohttp.Response.status |> Cohttp.Code.code_of_status in
if Cohttp.Code.is_success code then
if code = 404 then raise Status_Not_found
else if Cohttp.Code.is_success code then
let* b = Cohttp_lwt.Body.to_string body in
Lwt.return (Ok b)
else Lwt.return (Error (Cohttp.Code.reason_phrase_of_code code))
@ -228,7 +231,7 @@ let fetch_matches ctx =
ctx.id ctx.season order
|> get |> Yojson.Safe.from_string |> api_events_of_yojson
|> matches_of_api_events
with Failure str when str = "Not Found" -> [] (* FIXME *)
with Status_Not_found -> []
in
Tournament.make ctx (List.append (g "last") (g "next"))