go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/frontend/ui/src/tools/prpc_retrier.ts (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import { 16 GrpcError, 17 RpcCode, 18 } from '@chopsui/prpc-client'; 19 20 function isRetriable(e: GrpcError): boolean { 21 // The following codes indicate transient errors that are retriable. See: 22 // https://source.chromium.org/chromium/infra/infra/+/main:go/src/go.chromium.org/luci/grpc/grpcutil/errors.go;l=176?q=codeToStatus&type=cs 23 switch (e.code) { 24 case RpcCode.INTERNAL: 25 return true; 26 case RpcCode.UNKNOWN: 27 return true; 28 case RpcCode.UNAVAILABLE: 29 return true; 30 } 31 return false; 32 } 33 34 export function prpcRetrier(_failureCount: number, e: Error): boolean { 35 if (e instanceof GrpcError && isRetriable(e)) { 36 return true; 37 } 38 return false; 39 }