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(