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 {
|
pub type Error {
|
||||||
BadInstance
|
BadInstance
|
||||||
FetchError(error: Dynamic)
|
FetchError(error: Dynamic)
|
||||||
|
ResponseError(status: Int)
|
||||||
DecodeError(error: DecodeError)
|
DecodeError(error: DecodeError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
use req <- result.try(
|
||||||
httpc.send(req)
|
httpc.send(req)
|
||||||
|> result.map_error(apkallone.FetchError)
|
|> result.map_error(apkallone.FetchError),
|
||||||
|
)
|
||||||
|
|
||||||
|
case req.status {
|
||||||
|
200 -> Ok(req)
|
||||||
|
other -> Error(apkallone.ResponseError(other))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_response(
|
pub fn decode_response(
|
||||||
|
|
Loading…
Reference in a new issue