check response status

This commit is contained in:
lewdum 2024-10-22 18:38:36 -03:00
parent 3175040e3a
commit 16d3936c06
No known key found for this signature in database
2 changed files with 10 additions and 2 deletions

View file

@ -10,5 +10,6 @@ pub type Client {
pub type Error { pub type Error {
BadInstance BadInstance
FetchError(error: Dynamic) FetchError(error: Dynamic)
ResponseError(status: Int)
DecodeError(error: DecodeError) DecodeError(error: DecodeError)
} }

View file

@ -22,8 +22,15 @@ pub fn prepare_request(
} }
pub fn send_request(req: Request(String)) -> Result(Response(String), Error) { pub fn send_request(req: Request(String)) -> Result(Response(String), Error) {
httpc.send(req) use req <- result.try(
|> result.map_error(apkallone.FetchError) httpc.send(req)
|> result.map_error(apkallone.FetchError),
)
case req.status {
200 -> Ok(req)
other -> Error(apkallone.ResponseError(other))
}
} }
pub fn decode_response( pub fn decode_response(