How to pass reqwest Result to a function?

If I make a request with reqwest, I get a reqwest::error::Result<Response>:

let client = reqwest::blocking::Client::new();
let result = client.post("http://example.com").send();

I want to pass this result to a function, which will then determine the course of action. It will take into account not only the received response but also whether a response was received at all, that's why I want to pass the Result, not just the Response.

I tried this:

fn error_action(api_call_result: reqwest::error::Result<Response>) -> ErrorType {
}

But:

error[E0603]: module `error` is private
   --> src\b2.rs:62:44
    |
62  |     fn error_action(api_call_result: reqwest::error::Result<Response>) -> ErrorType {
    |                                               ^^^^^ private module

The Result alias appears to be exported from the crate root on v0.11.14. Did you try it without the error module in the path?

2 Likes

That's only for the async API I think?

error[E0308]: mismatched types
  --> src\b2.rs:52:28
   |
52 |         match Self::error_action(result) {
   |               ------------------ ^^^^^^ expected `reqwest::Response`, found `reqwest::blocking::Response`
   |               |
   |               arguments to this function are incorrect

That error is for the Response type, not the Result type. Did you import the blocking version of Response?

Oh, indeed, didn't see that.