SatoshiPortal / boltz-rust

Boltz client rust crate
https://docs.boltz.exchange
30 stars 16 forks source link

Error description not propagated in `post_swap_req`, `post_reverse_req` error #46

Closed ok300 closed 1 month ago

ok300 commented 1 month ago

If boltz_client::swaps::boltzv2::post_swap_req fails, it throws an boltz_client::error::Error::HTTP(err). Trying to print it on debug gives a vague

HTTP(Status(400, Response[status: 400, status_text: Bad Request, url: https://api.testnet.boltz.exchange/v2/swap/submarine]))

However the Boltz API endpoint^1 actually has an error field they return in case of errors:

{
  "error": "string"
}

Indeed, calling that endpoint via curl returns a detailed description of the error in the error field:

curl -X POST -H "Content-Type: application/json" --data "{\"invoiceAmount\":1000,\"preimageHash\":\"b62b2af3048bfafdbe117dc620385a6e37fd50a1fadd00de4a8225f0cb2f6b9d\",\"claimPublicKey\":\"03c111f407ca65b6535f7ca85208303887341809dbd4ba8d591ddc2a9c4567e34c\",\"pairHash\":\"976e6dad9097f657213244b046e5f29524b743568a2c3d569b421df1e07e1b44\",\"referralId\":\"boltz_webapp_desktop\",\"to\":\"L-BTC\",\"from\":\"BTC\"}" https://testnet.boltz.exchange/api/v2/swap/reverse 

{"error":"a swap with this preimage hash exists already"}

Please update the post_swap_req and post_reverse_req error handling, such that the error message from the Boltz API is included in the boltz_client::error::Error::HTTP error returned by the boltz client.

i5hi commented 1 month ago

I've updated this, can you confirm if you are still facing this issue?

ok300 commented 1 month ago

Works now, thanks!