fix namespace patch not found error message (#17242)

* fix namespace patch not found error message

* handle 404 in namespace patch cmd
This commit is contained in:
Chris Capurso
2022-09-23 10:41:11 -04:00
committed by GitHub
parent 63a91a8f5c
commit 6be838e9e2

View File

@@ -3,11 +3,12 @@ package command
import ( import (
"context" "context"
"fmt" "fmt"
"net/http"
"strings" "strings"
"github.com/posener/complete" "github.com/hashicorp/vault/api"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
"github.com/posener/complete"
) )
var ( var (
@@ -119,12 +120,12 @@ func (c *NamespacePatchCommand) Run(args []string) int {
secret, err := client.Logical().JSONMergePatch(context.Background(), "sys/namespaces/"+namespacePath, data) secret, err := client.Logical().JSONMergePatch(context.Background(), "sys/namespaces/"+namespacePath, data)
if err != nil { if err != nil {
c.UI.Error(fmt.Sprintf("Error patching namespace: %s", err)) if re, ok := err.(*api.ResponseError); ok && re.StatusCode == http.StatusNotFound {
return 2 c.UI.Error("Namespace not found")
} return 2
}
if secret == nil || secret.Data == nil { c.UI.Error(fmt.Sprintf("Error patching namespace: %s", err))
c.UI.Error(fmt.Sprintf("No namespace found: %s", err))
return 2 return 2
} }