We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
From the net/http package, export errTimeout, errRequestCanceled, and errRequestCanceledConn.
net/http
errTimeout
errRequestCanceled
errRequestCanceledConn
When making an http request with a timeout, the http client.Do throws an unexported errTimeout. This makes parsing the error problematic. For example:
http
client.Do
package main import ( "context" "fmt" "net/http" "time" ) func main() { client := http.DefaultClient request, _ := http.NewRequest("GET", "https://google.com", nil) ctx, _ := context.WithTimeout(context.Background(), 1*time.Millisecond) request = request.WithContext(ctx) if response, err := client.Do(request); err != nil { // Untyped error. Have to scrape error message to find out if it's a // timeout. fmt.Println(err) } else { fmt.Println(response.StatusCode) } }
It would be safer to export this error. For example:
package main import ( "context" "fmt" "net/http" "time" ) func main() { client := http.DefaultClient request, _ := http.NewRequest("GET", "https://google.com", nil) ctx, _ := context.WithTimeout(context.Background(), 1*time.Millisecond) request = request.WithContext(ctx) if response, err := client.Do(request); err != nil { // Untyped error. Have to scrape error message to find out if it's a // timeout. if err == http.ErrTimeout { // Retry request with a back off. } } else { fmt.Println(response.StatusCode) } }
The text was updated successfully, but these errors were encountered:
Assert if the error implements Timeout() and use that.
if err, ok := err.(net.Error); ok { if err.Timeout() { // whatever } }
Sorry, something went wrong.
Dup of #15935, #14203, #13667
@bradfitz I did a quick search and couldn't find a similar issue. Thanks for pointing those out.
@davecheney Thanks
No branches or pull requests
tl;dr
From the
net/http
package, exporterrTimeout
,errRequestCanceled
, anderrRequestCanceledConn
.Request timeout
When making an
http
request with a timeout, the httpclient.Do
throws an unexportederrTimeout
. This makes parsing the error problematic. For example:It would be safer to export this error. For example:
The text was updated successfully, but these errors were encountered: