go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/client/coordinator/errors.go (about) 1 // Copyright 2015 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 package coordinator 16 17 import ( 18 "errors" 19 20 "google.golang.org/grpc/codes" 21 "google.golang.org/grpc/status" 22 ) 23 24 var ( 25 // ErrNoAccess is returned from methods to indicate that the requested 26 // operation could not be performed because the user does not have access 27 // to that data or function. 28 ErrNoAccess = errors.New("coordinator: no access") 29 30 // ErrNoSuchStream is returned when the requested strem path does not exist. 31 ErrNoSuchStream = errors.New("coordinator: no such stream") 32 ) 33 34 func normalizeError(err error) error { 35 if err == nil { 36 return nil 37 } 38 switch status.Code(err) { 39 case codes.NotFound: 40 return ErrNoSuchStream 41 42 case codes.Unauthenticated, codes.PermissionDenied: 43 return ErrNoAccess 44 45 default: 46 return err 47 } 48 }