Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: common/lhttp/client.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: copyright Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: common/lhttp/client.go
diff --git a/common/lhttp/client.go b/common/lhttp/client.go
index 1835eb22b570ef831919f15f6209d1a8f14ee418..a904fa934e85ce553167a17f850273808bca6294 100644
--- a/common/lhttp/client.go
+++ b/common/lhttp/client.go
@@ -83,20 +83,20 @@ func NewRequest(ctx context.Context, c *http.Client, rFn retry.Factory, rgen Req
if err != nil {
// Retry every error. This is sad when you specify an invalid hostname but
// it's better than failing when DNS resolution is flaky.
- return errorHandler(nil, errors.WrapTransient(err))
+ return errorHandler(nil, retry.Tag.Apply(err))
}
status = resp.StatusCode
switch {
case status == 408, status == 429, status >= 500:
// The HTTP status code means the request should be retried.
- err = errors.WrapTransient(
- fmt.Errorf("http request failed: %s (HTTP %d)", http.StatusText(status), status))
+ err = errors.Reason("http request failed: %(text)s (HTTP %(code)d)").
+ D("text", http.StatusText(status)).D("code", status).Tag(retry.Tag).Err()
case status == 404 && strings.HasPrefix(req.URL.Path, "/_ah/api/"):
// Endpoints occasionally return 404 on valid requests!
logging.Infof(ctx, "lhttp.Do() got a Cloud Endpoints 404: %#v", resp.Header)
- err = errors.WrapTransient(
- fmt.Errorf("http request failed (endpoints): %s (HTTP %d)", http.StatusText(status), status))
+ err = errors.Reason("http request failed (endpoints): %(text)s (HTTP %(code)d)").
+ D("text", http.StatusText(status)).D("code", status).Tag(retry.Tag).Err()
case status >= 400:
// Any other failure code is a hard failure.
err = fmt.Errorf("http request failed: %s (HTTP %d)", http.StatusText(status), status)
@@ -157,7 +157,8 @@ func NewRequestJSON(ctx context.Context, c *http.Client, rFn retry.Factory, url,
}
if err := json.NewDecoder(resp.Body).Decode(out); err != nil {
// Retriable.
- return errors.WrapTransient(fmt.Errorf("bad response %s: %s", url, err))
+ return errors.Annotate(err).Reason("bad response %(url)s").
+ D("url", url).Tag(retry.Tag).Err()
}
return nil
}, nil), nil

Powered by Google App Engine
This is Rietveld 408576698