Closed simeg closed 4 years ago
If you follow redirects automatically, the intermediate statuses are discarded. err.status()
has nothing to do with redirects, it comes from Response::error_for_status()
, which converts 4xx and 5xx status codes into errors.
As the error you got describes, after following the redirect to HTTPS, the certificate verification fails.
That makes sense. However, wouldn't the certificate verification failure result in a 4xx
? I'm confused to why err.status()
doesn't provide any status code.
No, notice how the error says it's a Connect
error, it happened during the TLS handshake, before the server could send a response. You don't have any code calling response.error_for_status()
, so the error will not have been converted from a response's status code.
Is there a way to extract this type of error? I'm not sure I understand. I can't call response.error_for_status()
because client.head(url).send()
returns Err
for this URL.
Appreciate the help!
Let me see if we can back up some:
Error
?My code is interested in why the request failed, so I can let the user of my tool know what type of error occurred. In this case the TLS handshake fails but I can't find a way to know that in the code. I only know that by printing the error.
The intermediate status codes are not interesting, only the final one. Hope this makes more sense.
Is this error granularity not in scope for reqwest
? Should I use hyper
for this?
You can check the Error::source()
chain for more info. Looks like reqwest is missing an is_connect()
method as well.
Besides printing the error for the user, what would you hope to inspect?
Nice, using the source chain solves my problem. However it would be useful to get the status code, not only knowing it's a redirect error. Would you accept a PR for that change?
I'm thinking that error.status()
would provide this for all error types. WDYT? I could also implement the is_connect()
.
There is no status code, it was a connect error.
I mean for redirect and timeout errors.
Neither of those have status codes either. The only time an error contains a status code is when you convert an response into an error via Response::error_for_status()
.
Ah yes I see now, I misunderstood the Error
type. Closing this now - thanks for the help!
I'm writing a tool that checks a set of links for their HTTP statuses. I have a link that returns
301 Moved Permanently
if I set the redirect policy toPolicy::none()
, but if I leave it to default (allowing 10 redirects) I get an error where I cannot get the status code. See the code below.How can I capture the status code of a link that follows redirects? It feels like I'm missing something obvious here.