Unwrap grpc errors to make nicer user facing errors
This commit is contained in:
parent
b11acad1c9
commit
d47b83f80b
4 changed files with 18 additions and 14 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/pterm/pterm"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -47,7 +48,7 @@ var createNamespaceCmd = &cobra.Command{
|
|||
log.Trace().Interface("request", request).Msg("Sending CreateNamespace request")
|
||||
response, err := client.CreateNamespace(ctx, request)
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot create namespace: %s", err), output)
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot create namespace: %s", status.Convert(err).Message()), output)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,7 @@ var destroyNamespaceCmd = &cobra.Command{
|
|||
|
||||
response, err := client.DeleteNamespace(ctx, request)
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot destroy namespace: %s", err), output)
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot destroy namespace: %s", status.Convert(err).Message()), output)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -99,7 +100,7 @@ var listNamespacesCmd = &cobra.Command{
|
|||
|
||||
response, err := client.ListNamespaces(ctx, request)
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot get namespaces: %s", err), output)
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot get namespaces: %s", status.Convert(err).Message()), output)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -150,7 +151,7 @@ var renameNamespaceCmd = &cobra.Command{
|
|||
|
||||
response, err := client.RenameNamespace(ctx, request)
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot rename namespace: %s", err), output)
|
||||
ErrorOutput(err, fmt.Sprintf("Cannot rename namespace: %s", status.Convert(err).Message()), output)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue