You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to filter the error type from an error returned by client.Do(request), there is only the option to determine if it was a timeout. There is no other method to determine other specific types of errors.
client:=&http.Client{}
request, _:=http.NewRequest("GET", "https://example.org", nil)
response, err:=client.Do(request)
ifurlErr, ok:=err.(*url.Error); ok&&urlErr.Timeout() {
panic("Timeout!")
} elseiferr!=nil {
panic(err) // this could be a 'too many redirects' error
}
I managed to scrape the error myself with the strings.Contains(err.Error(), "stopped after 10 redirects") function, but this just isn't elegant at all and my cause collisions with other errors (or even strings).
The text was updated successfully, but these errors were encountered:
andybons
changed the title
net/url: Bool method to filter 'too many redirects' out of url.Error
proposal: net/url: add method to filter 'too many redirects' out of url.Error
Sep 29, 2020
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When trying to filter the error type from an error returned by
client.Do(request)
, there is only the option to determine if it was a timeout. There is no other method to determine other specific types of errors.What did you expect to see?
I managed to scrape the error myself with the
strings.Contains(err.Error(), "stopped after 10 redirects")
function, but this just isn't elegant at all and my cause collisions with other errors (or even strings).The text was updated successfully, but these errors were encountered: