| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. | 4 that can be found in the LICENSE file. |
| 5 --> | 5 --> |
| 6 | 6 |
| 7 <link rel="import" href="../rpc/rpc-error.html"> | 7 <link rel="import" href="../rpc/rpc-error.html"> |
| 8 | 8 |
| 9 <script> | 9 <script> |
| 10 "use strict"; | 10 "use strict"; |
| 11 | 11 |
| 12 function LogDogError(base) { | 12 function LogDogError(base) { |
| 13 this.base = base; | 13 this.base = base; |
| 14 }; | 14 }; |
| 15 LogDogError.wrapGrpc = function(err) { | 15 LogDogError.wrapGrpc = function(err) { |
| 16 if (err instanceof luci.rpc.GrpcError) { | 16 if (err instanceof luci.rpc.GrpcError) { |
| 17 return new LogDogError(err); | 17 return new LogDogError(err); |
| 18 } | 18 } |
| 19 return err; | 19 return err; |
| 20 } | 20 } |
| 21 | 21 |
| 22 LogDogError.prototype = Object.create(Error.prototype); | 22 LogDogError.prototype = Object.create(Error.prototype); |
| 23 LogDogError.prototype.isGrpcError = function() { | 23 LogDogError.prototype.isGrpcError = function() { |
| 24 return (this.base.name === "GrpcError"); | 24 return (this.base.name === "GrpcError"); |
| 25 }; | 25 }; |
| 26 LogDogError.prototype.isNotFound = function() { | 26 LogDogError.prototype.isNotFound = function() { |
| 27 return (this.isGrpcError() && this.base.code === luci.rpc.Code.NOT_FOUND); | 27 return (this.isGrpcError() && this.base.code === 5); |
| 28 }; | 28 }; |
| 29 LogDogError.prototype.isUnauthenticated = function() { | 29 LogDogError.prototype.isUnauthenticated = function() { |
| 30 return (this.isGrpcError() && | 30 return (this.isGrpcError() && this.base.code === 16); |
| 31 this.base.code === luci.rpc.Code.UNAUTHENTICATED); | |
| 32 }; | |
| 33 LogDogError.prototype.isTransient = function() { | |
| 34 if ( ! this.isGrpcError() ) { | |
| 35 return false; | |
| 36 } | |
| 37 switch ( this.base.code ) { | |
| 38 case luci.rpc.Code.INTERNAL: | |
| 39 case luci.rpc.Code.UNAVAILABLE: | |
| 40 case luci.rpc.Code.RESOURCE_EXHAUSTED: | |
| 41 return true; | |
| 42 | |
| 43 default: | |
| 44 return false; | |
| 45 } | |
| 46 }; | 31 }; |
| 47 </script> | 32 </script> |
| OLD | NEW |