From 6be838e9e2113ae27fc43fb569995d97b6c316af Mon Sep 17 00:00:00 2001 From: Chris Capurso <1036769+ccapurso@users.noreply.github.com> Date: Fri, 23 Sep 2022 10:41:11 -0400 Subject: [PATCH] fix namespace patch not found error message (#17242) * fix namespace patch not found error message * handle 404 in namespace patch cmd --- command/namespace_patch.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/command/namespace_patch.go b/command/namespace_patch.go index 6f5b8390f1..b404743a20 100644 --- a/command/namespace_patch.go +++ b/command/namespace_patch.go @@ -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 }