Skip to content

Commit

Permalink
Merge pull request #1480 from data-integrations/PLUGIN-1807-4
Browse files Browse the repository at this point in the history
[PLUGINk-1807] Add more detailed error in error message
  • Loading branch information
itsankit-google authored Jan 6, 2025
2 parents 489de36 + 2d8213f commit c5f4d69
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand Down

0 comments on commit c5f4d69

Please sign in to comment.