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

Side by Side Diff: scheduler/appengine/task/utils/apiclient.go

Issue 2951393002: [errors] de-specialize Transient in favor of Tags. (Closed)
Patch Set: more refactor Created 3 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package utils 5 package utils
6 6
7 import ( 7 import (
8 » "github.com/luci/luci-go/common/errors" 8 » "github.com/luci/luci-go/common/retry/transient"
9 "google.golang.org/api/googleapi" 9 "google.golang.org/api/googleapi"
10 ) 10 )
11 11
12 // IsTransientAPIError returns true if error from Google API client indicates 12 // IsTransientAPIError returns true if error from Google API client indicates
13 // an error that can go away on its own in the future. 13 // an error that can go away on its own in the future.
14 func IsTransientAPIError(err error) bool { 14 func IsTransientAPIError(err error) bool {
15 if err == nil { 15 if err == nil {
16 return false 16 return false
17 } 17 }
18 apiErr, _ := err.(*googleapi.Error) 18 apiErr, _ := err.(*googleapi.Error)
19 if apiErr == nil { 19 if apiErr == nil {
20 return true // failed to get HTTP code => connectivity error => transient 20 return true // failed to get HTTP code => connectivity error => transient
21 } 21 }
22 return apiErr.Code >= 500 || apiErr.Code == 429 || apiErr.Code == 0 22 return apiErr.Code >= 500 || apiErr.Code == 429 || apiErr.Code == 0
23 } 23 }
24 24
25 // WrapAPIError wraps error from Google API client in transient wrapper if 25 // WrapAPIError wraps error from Google API client in transient wrapper if
26 // necessary. 26 // necessary.
27 func WrapAPIError(err error) error { 27 func WrapAPIError(err error) error {
28 if IsTransientAPIError(err) { 28 if IsTransientAPIError(err) {
29 » » return errors.WrapTransient(err) 29 » » return transient.Tag.Apply(err)
30 } 30 }
31 return err 31 return err
32 } 32 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698