Reqwest: error with response body message

Created on 22 Sep 2020  路  6Comments  路  Source: seanmonstar/reqwest

Basically we need this for https://github.com/gsquire/sendgrid-rs/pull/69, https://github.com/gsquire/sendgrid-rs/issues/66

We were doing resp.text() there, but I don't think it's good enough, reqwest should offer a way to get response body while error happens. Maybe have a way to enrich resp.error_for_status_code

Any idea on this?

All 6 comments

Could you say more what the problem is? I don't understand what exactly you're trying to do.

@seanmonstar Hi, basically with current error_for_status_code we can only have url and status code in error message, but we are not able to understand what exactly happened.

That's why we want response body to be able to know the exact error

You could read the body and include that in your own error type.

I don't think error_for_status should default to reading the entire body, users may not require that. If you still want to use that convenience method, you could use error_for_status_ref and then still read the body.

@seanmonstar I don't think we should by default read the whole body neither, I'm wondering if you mind having a new method to manage this?

We could possibly add a new method, but I'd like to encourage trying to solve it like I mentioned first in your app/library. If it were a very common pattern, then we could consider adding it here.

@seanmonstar Thanks finally I applied your advice

Was this page helpful?
0 / 5 - 0 ratings

Related issues

richardanaya picture richardanaya  路  5Comments

AmarOk1412 picture AmarOk1412  路  5Comments

samuela picture samuela  路  5Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  路  6Comments

hwchen picture hwchen  路  4Comments