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
{{ message }}
This repository was archived by the owner on Nov 6, 2026. It is now read-only.
Package errorutil allows errors to be tagged, allowing calling code to make decisions,
such as "is the error retryable ?" or "what kind of HTTP status code should I return ?".
Retryable errors
Mark errors as retryable :
func foo() error {
err := bar()
if err != nil {
// should be retried
return errorutil.RetryableError(err)
}
return baz() // should not be retried
}
func main() {
err := foo()
if errorutil.IsRetryable(err) {
// retry !
}
}
HTTP Aware errors
Build an error based on a http.Response. It will be retryable of status code is http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusServiceUnavailable, http.StatusInternalServerError or 429 (Too many requests).
resp, err := http.Get("http://www.example.com")
if err != nil {
// return error
}
defer resp.Body.Close()
if err := errorutil.HTTPError(resp); err != nil {
// return error
}
// handle response
Find the most appropriate status code for an error :