mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-16 10:40:38 +08:00
Updated namespace_server.go to use GRPCError()
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
@@ -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{}
|
||||||
|
Reference in New Issue
Block a user