From 2d8213f7106e4d19898bc8e9590037fdd6b0ee07 Mon Sep 17 00:00:00 2001 From: itsankit-google Date: Mon, 6 Jan 2025 09:56:56 +0000 Subject: [PATCH] Add more detailed error in error message --- .../gcp/common/GCPErrorDetailsProvider.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/cdap/plugin/gcp/common/GCPErrorDetailsProvider.java b/src/main/java/io/cdap/plugin/gcp/common/GCPErrorDetailsProvider.java index 678544351..06c7c2115 100644 --- a/src/main/java/io/cdap/plugin/gcp/common/GCPErrorDetailsProvider.java +++ b/src/main/java/io/cdap/plugin/gcp/common/GCPErrorDetailsProvider.java @@ -74,16 +74,14 @@ public ProgramFailureException getExceptionDetails(Exception e, ErrorContext err private ProgramFailureException getProgramFailureException(HttpResponseException e, ErrorContext errorContext) { Integer statusCode = e.getStatusCode(); ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(statusCode); - String errorReason = String.format("%s %s %s", e.getStatusCode(), e.getStatusMessage(), + String errorReason = String.format("%s %s. %s", e.getStatusCode(), e.getStatusMessage(), pair.getCorrectiveAction()); String errorMessageFormat = "Error occurred in the phase: '%s'. Error message: %s"; String errorMessage = e.getMessage(); String externalDocumentationLink = null; if (e instanceof GoogleJsonResponseException) { - GoogleJsonResponseException exception = (GoogleJsonResponseException) e; - errorMessage = exception.getDetails() != null ? exception.getDetails().getMessage() : - exception.getMessage(); + errorMessage = getErrorMessage((GoogleJsonResponseException) e); externalDocumentationLink = getExternalDocumentationLink(); if (!Strings.isNullOrEmpty(externalDocumentationLink)) { @@ -102,6 +100,17 @@ private ProgramFailureException getProgramFailureException(HttpResponseException externalDocumentationLink, e); } + private String getErrorMessage(GoogleJsonResponseException exception) { + if (exception.getDetails() != null) { + try { + return exception.getDetails().toPrettyString(); + } catch (IOException e) { + return exception.getDetails().toString(); + } + } + return exception.getMessage(); + } + /** * Get a ProgramFailureException with the given error