-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
?
on surf::Exception
#35
Comments
This is because Surf is using a silly choice of error type. :( http-rs/surf#86 For now you can work around this by avoiding use anyhow::{bail, Result};
async fn some_request() -> Result<()> {
let _response = match surf::get("https://www.rust-lang.org").await {
Ok(response) => response,
Err(err) => bail!(err),
};
...
} |
Thanks! |
I know this is closed, but I found myself here recently so I thought I'd share another approach. use anyhow::{anyhow, Context, Result};
async fn some_request() -> Result<()> {
let _response = surf::get("https://www.rust-lang.org")
.await
.map_err(|err| anyhow!(err)) // TODO: Remove me when surf 2.0 is released
.context("Failed to fetch from rust-lang.org")?;
...
} |
I'm working on a simple app using async/await and Surf, and I can't seem to use it with anyhow.
Here's a minimal example:
cargo +beta check
complains with:I can't tell if this is an issue with
anyhow
, withsurf
, with the.await
, or if I'm doing something wrong.The text was updated successfully, but these errors were encountered: