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 efe5193a59
commit 073018e372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

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