Skip to content

Commit

Permalink
Merge pull request #50 from ok300/ok300-fix-post-error-mgmt-on-http-e…
Browse files Browse the repository at this point in the history
…rror-codes

Correctly return error on POST requests that fail with HTTP error code
  • Loading branch information
i5hi authored Jun 6, 2024
2 parents 9c3fd15 + bd70eac commit feb17d3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/swaps/boltzv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ impl BoltzApiClientV2 {
.send_json(data)
{
Ok(r) => {
println!("{:#?}", r);
log::debug!("POST response: {:#?}", r);
r.into_string()?
}
Err(ureq::Error::Status(code, response)) => {
print!("{:#?}", response);
let error: Value = serde_json::from_str(&response.into_string()?)?;
error.get("error").unwrap_or(&Value::Null).to_string()
}
Err(e) => {
print!("{:#?}", e);
return Err(e.into());
Err(ureq_err) => {
log::error!("POST error: {:#?}", ureq_err);
let err = match ureq_err {
ureq::Error::Status(_code, err_resp) => {
let e_val: Value = serde_json::from_str(&err_resp.into_string()?)?;
let e_str = e_val.get("error").unwrap_or(&Value::Null).to_string();
Error::HTTP(e_str)
}
ureq::Error::Transport(_) => ureq_err.into(),
};
return Err(err.into());
}
};
response
Expand Down

0 comments on commit feb17d3

Please sign in to comment.