ureq icon indicating copy to clipboard operation
ureq copied to clipboard

Request::into_string changes error type

Open lolgesten opened this issue 3 years ago • 1 comments

This code is currently impossible.

ureq::get(ZONE_URL)
          .call()
          .and_then(|resp| {
              resp.into_string().map(|s| s[0..(s.len() - 1)].to_string())
          })

Because .call() returns a Result<ureq::Response, ureq::Error> and into_string() does Result<String, io::Error>.

mismatched types
expected enum `std::result::Result<_, ureq::Error>`
   found enum `std::result::Result<std::string::String, std::io::Error>`

I'm unsure why we used the io errors on these into_xxx, maybe just inertia? To fix it would be a breaking change, so maybe park for the future…

lolgesten avatar Jan 26 '21 10:01 lolgesten

It honestly didn't occur to me that we could change it. The main thing going on in into_string() is reading, which produces io::Error. But of course, ureq::error::Transport can hold an io::Error. Agree on parking for the future.

jsha avatar Jan 26 '21 17:01 jsha