Skip to content

Commit ddfaf89

Browse files
committed
Add errorReason/errorMessage
1 parent 547bfae commit ddfaf89

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

src/main/java/io/cdap/plugin/gcp/common/GCPErrorDetailsProvider.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
package io.cdap.plugin.gcp.common;
1818

19-
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
2019
import com.google.api.client.http.HttpResponseException;
21-
import com.google.common.base.Strings;
2220
import com.google.common.base.Throwables;
2321
import io.cdap.cdap.api.exception.ErrorCategory;
2422
import io.cdap.cdap.api.exception.ErrorCategory.ErrorCategoryEnum;
@@ -73,32 +71,12 @@ public ProgramFailureException getExceptionDetails(Exception e, ErrorContext err
7371
*/
7472
private ProgramFailureException getProgramFailureException(HttpResponseException e,
7573
ErrorContext errorContext) {
76-
Integer statusCode = e.getStatusCode();
77-
ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(statusCode);
78-
String errorReason = String.format("%s %s. %s", e.getStatusCode(), e.getStatusMessage(),
79-
pair.getCorrectiveAction());
80-
81-
String errorMessage = e.getMessage();
82-
String externalDocumentationLink = null;
83-
if (e instanceof GoogleJsonResponseException) {
84-
errorMessage = GCPErrorDetailsProviderUtil.getErrorMessage((GoogleJsonResponseException) e);
85-
86-
externalDocumentationLink = getExternalDocumentationLink();
87-
if (!Strings.isNullOrEmpty(externalDocumentationLink)) {
88-
89-
if (!errorReason.endsWith(".")) {
90-
errorReason = errorReason + ".";
91-
}
92-
errorReason = String.format("%s For more details, see %s", errorReason,
93-
externalDocumentationLink);
94-
}
95-
}
96-
9774
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategoryEnum.PLUGIN),
98-
errorReason, String.format(ERROR_MESSAGE_FORMAT, errorContext.getPhase(),
99-
e.getClass().getName(), errorMessage),
100-
pair.getErrorType(), true, ErrorCodeType.HTTP, statusCode.toString(),
101-
externalDocumentationLink, e);
75+
GCPErrorDetailsProviderUtil.getErrorReason(e, getExternalDocumentationLink()),
76+
String.format(ERROR_MESSAGE_FORMAT, errorContext.getPhase(), e.getClass().getName(),
77+
GCPErrorDetailsProviderUtil.getErrorMessage(e)),
78+
ErrorUtils.getActionErrorByStatusCode(e.getStatusCode()).getErrorType(), true, ErrorCodeType.HTTP,
79+
Integer.toString(e.getStatusCode()), getExternalDocumentationLink(), e);
10280
}
10381

10482
/**

src/main/java/io/cdap/plugin/gcp/common/GCPErrorDetailsProviderUtil.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,33 @@ public static ProgramFailureException getHttpResponseExceptionDetailsFromChain(E
6060
}
6161

6262
private static ProgramFailureException getProgramFailureException(HttpResponseException e, String externalDocUrl) {
63-
Integer statusCode = e.getStatusCode();
64-
ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(statusCode);
65-
String errorReason =
66-
String.format("%s %s. %s", e.getStatusCode(), e.getStatusMessage(), pair.getCorrectiveAction());
67-
String errorMessage = e.getMessage();
63+
String errorReason = getErrorReason(e, externalDocUrl);
64+
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason,
65+
String.format("%s %s: %s", errorReason, e.getClass().getName(), getErrorMessage(e)),
66+
ErrorUtils.getActionErrorByStatusCode(e.getStatusCode()).getErrorType(), true, ErrorCodeType.HTTP,
67+
Integer.toString(e.getStatusCode()), externalDocUrl, e);
68+
}
69+
70+
static String getErrorMessage(HttpResponseException e) {
6871
if (e instanceof GoogleJsonResponseException) {
69-
errorMessage = getErrorMessage((GoogleJsonResponseException) e);
70-
if (!Strings.isNullOrEmpty(externalDocUrl)) {
71-
if (!errorReason.endsWith(".")) {
72-
errorReason = errorReason + ".";
73-
}
74-
errorReason = String.format("%s For more details, see %s", errorReason, GCPUtils.GCS_SUPPORTED_DOC_URL);
72+
return getErrorMessage((GoogleJsonResponseException) e);
73+
}
74+
return e.getMessage();
75+
}
76+
77+
static String getErrorReason(HttpResponseException e, String externalDocUrl) {
78+
String errorReason = String.format("%s %s. %s", e.getStatusCode(), e.getStatusMessage(),
79+
ErrorUtils.getActionErrorByStatusCode(e.getStatusCode()).getCorrectiveAction());
80+
if (!Strings.isNullOrEmpty(externalDocUrl)) {
81+
if (!errorReason.endsWith(".")) {
82+
errorReason = errorReason + ".";
7583
}
84+
errorReason = String.format("%s For more details, see %s", errorReason, externalDocUrl);
7685
}
77-
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason,
78-
String.format("%s %s: %s", errorReason, e.getClass().getName(), errorMessage), pair.getErrorType(), true,
79-
ErrorCodeType.HTTP, statusCode.toString(), GCPUtils.GCS_SUPPORTED_DOC_URL, e);
86+
return errorReason;
8087
}
8188

82-
static String getErrorMessage(GoogleJsonResponseException exception) {
89+
private static String getErrorMessage(GoogleJsonResponseException exception) {
8390
if (!Strings.isNullOrEmpty(exception.getMessage())) {
8491
return exception.getMessage();
8592
}

0 commit comments

Comments
 (0)