From e51550aedc02f1ad6038678fba5b8c4dcc753bad Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 13 Nov 2024 20:03:51 +0100 Subject: [PATCH] if there's a http error, return the error --- mirage/unikernel.ml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mirage/unikernel.ml b/mirage/unikernel.ml index f66de84..11a95ce 100644 --- a/mirage/unikernel.ml +++ b/mirage/unikernel.ml @@ -309,12 +309,15 @@ module Make (* XXX: we may be in trouble if different hash functions are used for the same archive *) let ( >>>= ) = Lwt_result.bind in fun response r data -> - Lwt.return r >>>= fun (digests, swap) -> - let digests = Archive_checksum.update_digests digests data in - active_add_bytes url (String.length data); - Swap.append swap data >|= function - | Ok () -> Ok (digests, swap) - | Error swap_err -> Error (`Swap swap_err) + if Http_mirage_client.Status.is_successful response.Http_mirage_client.status then + Lwt.return r >>>= fun (digests, swap) -> + let digests = Archive_checksum.update_digests digests data in + active_add_bytes url (String.length data); + Swap.append swap data >|= function + | Ok () -> Ok (digests, swap) + | Error swap_err -> Error (`Swap swap_err) + else + Lwt.return (Error `Bad_response) let check_csums_digests csums digests = let csums' = Archive_checksum.digests_to_hm digests in