check response status
This commit is contained in:
parent
3175040e3a
commit
16d3936c06
2 changed files with 10 additions and 2 deletions
|
@ -10,5 +10,6 @@ pub type Client {
|
|||
pub type Error {
|
||||
BadInstance
|
||||
FetchError(error: Dynamic)
|
||||
ResponseError(status: Int)
|
||||
DecodeError(error: DecodeError)
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue