From 97abc12f7ddb5f08ec7002cd12970272e95c7983 Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 24 Sep 2024 13:05:24 +0200 Subject: [PATCH] Add error detail to error reporting, when available Signed-off-by: Kobi Samoray --- nsxt/policy_errors.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nsxt/policy_errors.go b/nsxt/policy_errors.go index 79c4db4da..1d3753e1f 100644 --- a/nsxt/policy_errors.go +++ b/nsxt/policy_errors.go @@ -17,19 +17,21 @@ import ( ) func printAPIError(apiError model.ApiError) string { - if apiError.ErrorMessage != nil && apiError.ErrorCode != nil { - return fmt.Sprintf("%s (code %v)", *apiError.ErrorMessage, *apiError.ErrorCode) - } + msg := "" if apiError.ErrorMessage != nil { - return *apiError.ErrorMessage + msg = *apiError.ErrorMessage + } + + if apiError.Details != nil { + msg += fmt.Sprintf(": %s", *apiError.Details) } if apiError.ErrorCode != nil { - return fmt.Sprintf("(code %v)", *apiError.ErrorCode) + msg += fmt.Sprintf(" (code %v)", *apiError.ErrorCode) } - return "" + return msg } // TODO: Remove duplicate code when sdk implements composition of API inheritance model