From 16d3936c063550ff43ee0e9b817d559c65bc1a12 Mon Sep 17 00:00:00 2001 From: lewdum Date: Tue, 22 Oct 2024 18:38:36 -0300 Subject: [PATCH] check response status --- src/apkallone.gleam | 1 + src/apkallone/internal.gleam | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/apkallone.gleam b/src/apkallone.gleam index 67abb4c..e40b731 100644 --- a/src/apkallone.gleam +++ b/src/apkallone.gleam @@ -10,5 +10,6 @@ pub type Client { pub type Error { BadInstance FetchError(error: Dynamic) + ResponseError(status: Int) DecodeError(error: DecodeError) } diff --git a/src/apkallone/internal.gleam b/src/apkallone/internal.gleam index 646f5b6..f039caa 100644 --- a/src/apkallone/internal.gleam +++ b/src/apkallone/internal.gleam @@ -22,8 +22,15 @@ pub fn prepare_request( } pub fn send_request(req: Request(String)) -> Result(Response(String), Error) { - httpc.send(req) - |> result.map_error(apkallone.FetchError) + use req <- result.try( + httpc.send(req) + |> result.map_error(apkallone.FetchError), + ) + + case req.status { + 200 -> Ok(req) + other -> Error(apkallone.ResponseError(other)) + } } pub fn decode_response(