add service
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 2m55s
All checks were successful
Deploy Smart Search Backend Test / deploy (push) Successful in 2m55s
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -88,20 +89,31 @@ func ToGRPCError(err error, zapLogger *zap.Logger, method string) error {
|
||||
return status.Error(codes.Internal, "internal server error")
|
||||
}
|
||||
|
||||
var grpcCode codes.Code
|
||||
switch appErr.Code {
|
||||
case AuthInvalidCredentials, AuthMissing, AuthInvalidToken, RefreshInvalid:
|
||||
return status.Error(codes.Unauthenticated, appErr.Message)
|
||||
grpcCode = codes.Unauthenticated
|
||||
case PermissionDenied:
|
||||
return status.Error(codes.PermissionDenied, appErr.Message)
|
||||
grpcCode = codes.PermissionDenied
|
||||
case InviteLimitReached:
|
||||
return status.Error(codes.ResourceExhausted, appErr.Message)
|
||||
case InsufficientBalance, InviteInvalidOrExpired:
|
||||
return status.Error(codes.FailedPrecondition, appErr.Message)
|
||||
grpcCode = codes.ResourceExhausted
|
||||
case InsufficientBalance:
|
||||
grpcCode = codes.FailedPrecondition
|
||||
case InviteInvalidOrExpired:
|
||||
grpcCode = codes.NotFound
|
||||
case EmailAlreadyExists:
|
||||
return status.Error(codes.AlreadyExists, appErr.Message)
|
||||
grpcCode = codes.AlreadyExists
|
||||
case UserNotFound, RequestNotFound:
|
||||
return status.Error(codes.NotFound, appErr.Message)
|
||||
grpcCode = codes.NotFound
|
||||
default:
|
||||
return status.Error(codes.Unknown, appErr.Message)
|
||||
grpcCode = codes.Unknown
|
||||
}
|
||||
|
||||
st, err := status.New(grpcCode, appErr.Message).WithDetails(&errdetails.ErrorInfo{
|
||||
Reason: appErr.Code,
|
||||
})
|
||||
if err != nil {
|
||||
return status.Error(grpcCode, appErr.Message)
|
||||
}
|
||||
return st.Err()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user