mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-19 03:44:34 +08:00
Updated namespace_server.go to use GRPCError()
This commit is contained in:
@@ -2,8 +2,10 @@ package manager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/onepanelio/core/util"
|
||||
"github.com/onepanelio/core/util/logging"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
||||
"github.com/onepanelio/core/model"
|
||||
)
|
||||
@@ -18,6 +20,7 @@ func (r *ResourceManager) ListNamespaces() (namespaces []*model.Namespace, err e
|
||||
logging.Logger.Log.WithFields(log.Fields{
|
||||
"Error": err.Error(),
|
||||
}).Error("ListNamespaces failed.")
|
||||
err = util.NewUserError(codes.Unknown, "List namespaces failed.")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@@ -2,13 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/onepanelio/core/api"
|
||||
"github.com/onepanelio/core/manager"
|
||||
"github.com/onepanelio/core/model"
|
||||
"github.com/onepanelio/core/util"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
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) {
|
||||
namespaces, err := s.resourceManager.ListNamespaces()
|
||||
if err != nil {
|
||||
return nil, util.NewUserError(codes.Unknown, "Unknown error.")
|
||||
if errors.As(err, &userError) {
|
||||
return nil, userError.GRPCError()
|
||||
}
|
||||
}
|
||||
|
||||
apiNamespaces := []*api.Namespace{}
|
||||
|
Reference in New Issue
Block a user