| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 grpcutil | 5 package grpcutil |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "google.golang.org/grpc" | 8 "google.golang.org/grpc" |
| 9 "google.golang.org/grpc/codes" | 9 "google.golang.org/grpc/codes" |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 if IsTransientCode(Code(err)) { | 84 if IsTransientCode(Code(err)) { |
| 85 err = transient.Tag.Apply(err) | 85 err = transient.Tag.Apply(err) |
| 86 } | 86 } |
| 87 return err | 87 return err |
| 88 } | 88 } |
| 89 | 89 |
| 90 type grpcCodeTag struct{ Key errors.TagKey } | 90 type grpcCodeTag struct{ Key errors.TagKey } |
| 91 | 91 |
| 92 func (g grpcCodeTag) With(code codes.Code) errors.TagValue { return errors.MkTag
Value(g.Key, code) } | 92 func (g grpcCodeTag) With(code codes.Code) errors.TagValue { |
| 93 » return errors.TagValue{Key: g.Key, Value: code} |
| 94 } |
| 93 func (g grpcCodeTag) In(err error) (v codes.Code, ok bool) { | 95 func (g grpcCodeTag) In(err error) (v codes.Code, ok bool) { |
| 94 d, ok := errors.TagValueIn(g.Key, err) | 96 d, ok := errors.TagValueIn(g.Key, err) |
| 95 if ok { | 97 if ok { |
| 96 v = d.(codes.Code) | 98 v = d.(codes.Code) |
| 97 } | 99 } |
| 98 return | 100 return |
| 99 } | 101 } |
| 100 | 102 |
| 101 // Tag may be used to associate a gRPC status code with this error. | 103 // Tag may be used to associate a gRPC status code with this error. |
| 102 // | 104 // |
| (...skipping 20 matching lines...) Expand all Loading... |
| 123 // transient gRPC error type. | 125 // transient gRPC error type. |
| 124 func IsTransientCode(code codes.Code) bool { | 126 func IsTransientCode(code codes.Code) bool { |
| 125 switch code { | 127 switch code { |
| 126 case codes.Internal, codes.Unknown, codes.Unavailable: | 128 case codes.Internal, codes.Unknown, codes.Unavailable: |
| 127 return true | 129 return true |
| 128 | 130 |
| 129 default: | 131 default: |
| 130 return false | 132 return false |
| 131 } | 133 } |
| 132 } | 134 } |
| OLD | NEW |