github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/pkg/grpc/errors.go (about) 1 /*This file is part of kuberpult. 2 3 Kuberpult is free software: you can redistribute it and/or modify 4 it under the terms of the Expat(MIT) License as published by 5 the Free Software Foundation. 6 7 Kuberpult is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 MIT License for more details. 11 12 You should have received a copy of the MIT License 13 along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. 14 15 Copyright 2023 freiheit.com*/ 16 17 package grpc 18 19 import ( 20 "context" 21 22 "github.com/freiheit-com/kuberpult/pkg/logger" 23 "go.uber.org/zap" 24 "google.golang.org/grpc/codes" 25 "google.golang.org/grpc/status" 26 ) 27 28 func InternalError(ctx context.Context, err error) error { 29 logger := logger.FromContext(ctx) 30 logger.Error("grpc.internal", zap.Error(err)) 31 return status.Error(codes.Internal, "internal error") 32 } 33 34 func PublicError(_ context.Context, err error) error { 35 return status.Error(codes.InvalidArgument, "error: "+err.Error()) 36 } 37 38 func CanceledError(_ context.Context, err error) error { 39 return status.Error(codes.Canceled, err.Error()) 40 } 41 42 func FailedPrecondition(_ context.Context, err error) error { 43 return status.Error(codes.FailedPrecondition, "error: "+err.Error()) 44 } 45 46 func AuthError(_ context.Context, err error) error { 47 return status.Error(codes.Unauthenticated, "error: "+err.Error()) 48 } 49 50 func NotFoundError(_ context.Context, err error) error { 51 return status.Error(codes.NotFound, "error: "+err.Error()) 52 }