Updated namespace_server.go to use GRPCError()

This commit is contained in:
Aleksandr Melnikov
2020-02-10 16:27:28 -08:00
parent 1e7f034384
commit b0cea10a08
2 changed files with 7 additions and 3 deletions

View File

@@ -2,8 +2,10 @@ package manager
import ( import (
"fmt" "fmt"
"github.com/onepanelio/core/util"
"github.com/onepanelio/core/util/logging" "github.com/onepanelio/core/util/logging"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"github.com/onepanelio/core/model" "github.com/onepanelio/core/model"
) )
@@ -18,6 +20,7 @@ func (r *ResourceManager) ListNamespaces() (namespaces []*model.Namespace, err e
logging.Logger.Log.WithFields(log.Fields{ logging.Logger.Log.WithFields(log.Fields{
"Error": err.Error(), "Error": err.Error(),
}).Error("ListNamespaces failed.") }).Error("ListNamespaces failed.")
err = util.NewUserError(codes.Unknown, "List namespaces failed.")
} }
return return
} }

View File

@@ -2,13 +2,12 @@ package server
import ( import (
"context" "context"
"errors"
"github.com/golang/protobuf/ptypes/empty" "github.com/golang/protobuf/ptypes/empty"
"github.com/onepanelio/core/api" "github.com/onepanelio/core/api"
"github.com/onepanelio/core/manager" "github.com/onepanelio/core/manager"
"github.com/onepanelio/core/model" "github.com/onepanelio/core/model"
"github.com/onepanelio/core/util"
"google.golang.org/grpc/codes"
) )
type NamespaceServer struct { type NamespaceServer struct {
@@ -30,7 +29,9 @@ func apiNamespace(ns *model.Namespace) (namespace *api.Namespace) {
func (s *NamespaceServer) ListNamespaces(ctx context.Context, empty *empty.Empty) (*api.ListNamespacesResponse, error) { func (s *NamespaceServer) ListNamespaces(ctx context.Context, empty *empty.Empty) (*api.ListNamespacesResponse, error) {
namespaces, err := s.resourceManager.ListNamespaces() namespaces, err := s.resourceManager.ListNamespaces()
if err != nil { if err != nil {
return nil, util.NewUserError(codes.Unknown, "Unknown error.") if errors.As(err, &userError) {
return nil, userError.GRPCError()
}
} }
apiNamespaces := []*api.Namespace{} apiNamespaces := []*api.Namespace{}