Skip to content

Commit

Permalink
Revert "tweak diagnostics (#1479)"
Browse files Browse the repository at this point in the history
This reverts commit 1559ea9.
  • Loading branch information
carnellj-genesys authored Jan 15, 2025
1 parent 1559ea9 commit d90be7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions genesyscloud/util/util_diagnostic_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestUnitTestAPIResponseDiagWithBadApiResponse(t *testing.T) {
}

targetDiag := &detailedDiagnosticInfo{}
targetResponse := "{\"resourceType\":\"genesyscloud_tf_exporter\",\"statusCode\":500,\"errorMessage\":\"DummyError\",\"correlationId\":\"e03b48a1-7063-4ae2-921a-f64c8e02702b\"}"
targetResponse := "{\"resourceType\":\"genesyscloud_tf_exporter\",\"errorMessage\":\"Unable to build a message from the response because the APIResponse does not contain the appropriate data.\"}"
json.Unmarshal([]byte(targetResponse), targetDiag)

diag := BuildAPIDiagnosticError(resourceType, sumErrMsg, apiResponse)
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestUnitTestAPIResponseWithRetriesDiagWithBadApiResponse(t *testing.T) {
}

targetDiag := &detailedDiagnosticInfo{}
targetResponse := "{\"resourceType\":\"genesyscloud_tf_exporter\",\"statusCode\":500,\"errorMessage\":\"DummyError\",\"correlationId\":\"e03b48a1-7063-4ae2-921a-f64c8e02702b\"}"
targetResponse := "{\"resourceType\":\"genesyscloud_tf_exporter\",\"errorMessage\":\"Unable to build a message from the response because the APIResponse does not contain the appropriate data.\"}"
_ = json.Unmarshal([]byte(targetResponse), targetDiag)

diag := BuildWithRetriesApiDiagnosticError(resourceType, sumErrMsg, apiResponse)
Expand Down
13 changes: 4 additions & 9 deletions genesyscloud/util/util_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,19 @@ type detailedDiagnosticInfo struct {
}

func convertResponseToWrapper(resourceType string, apiResponse *platformclientv2.APIResponse) *detailedDiagnosticInfo {
detailedDiagnosticInfo := &detailedDiagnosticInfo{
return &detailedDiagnosticInfo{
ResourceType: resourceType,
Method: apiResponse.Response.Request.Method,
Path: apiResponse.Response.Request.URL.Path,
StatusCode: apiResponse.StatusCode,
ErrorMessage: apiResponse.ErrorMessage,
CorrelationID: apiResponse.CorrelationID,
}
if apiResponse.Response != nil && apiResponse.Response.Request != nil {
detailedDiagnosticInfo.Method = apiResponse.Response.Request.Method
if apiResponse.Response.Request.URL != nil {
detailedDiagnosticInfo.Path = apiResponse.Response.Request.URL.Path
}
}
return detailedDiagnosticInfo
}

func BuildAPIDiagnosticError(resourceType string, summary string, apiResponse *platformclientv2.APIResponse) diag.Diagnostics {
//Checking to make sure we have properly formed response
if apiResponse == nil {
if apiResponse == nil || apiResponse.Response == nil || apiResponse.Response.Request == nil || apiResponse.Response.Request.URL == nil {
error := fmt.Errorf("Unable to build a message from the response because the APIResponse does not contain the appropriate data.%s", "")
return BuildDiagnosticError(resourceType, summary, error)
}
Expand Down

0 comments on commit d90be7a

Please sign in to comment.