Skip to content

Commit 547bfae

Browse files
committed
Pass doc link as param
1 parent 1313714 commit 547bfae

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,39 @@
3535
*/
3636
public final class GCPErrorDetailsProviderUtil {
3737

38-
public static ProgramFailureException getHttpResponseExceptionDetailsFromChain(Exception e, String errorReason) {
39-
return getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.USER, true);
38+
public static ProgramFailureException getHttpResponseExceptionDetailsFromChain(Exception e, String errorReason,
39+
String externalDocUrl) {
40+
return getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.USER, true, externalDocUrl);
4041
}
4142

4243
public static ProgramFailureException getHttpResponseExceptionDetailsFromChain(Exception e, String errorReason,
4344
ErrorType errorType,
44-
boolean dependency) {
45+
boolean dependency,
46+
String externalDocUrl) {
4547
List<Throwable> causalChain = Throwables.getCausalChain(e);
4648
for (Throwable t : causalChain) {
4749
if (t instanceof ProgramFailureException) {
4850
// Avoid double wrap
4951
return (ProgramFailureException) t;
5052
}
5153
if (t instanceof HttpResponseException) {
52-
return getProgramFailureException((HttpResponseException) t);
54+
return getProgramFailureException((HttpResponseException) t, externalDocUrl);
5355
}
5456
}
5557
// If no HttpResponseException found in the causal chain, return generic program failure exception
5658
return ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason,
5759
String.format("%s %s: %s", errorReason, e.getClass().getName(), e.getMessage()), errorType, dependency, e);
5860
}
5961

60-
private static ProgramFailureException getProgramFailureException(HttpResponseException e) {
62+
private static ProgramFailureException getProgramFailureException(HttpResponseException e, String externalDocUrl) {
6163
Integer statusCode = e.getStatusCode();
6264
ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(statusCode);
6365
String errorReason =
6466
String.format("%s %s. %s", e.getStatusCode(), e.getStatusMessage(), pair.getCorrectiveAction());
6567
String errorMessage = e.getMessage();
6668
if (e instanceof GoogleJsonResponseException) {
6769
errorMessage = getErrorMessage((GoogleJsonResponseException) e);
68-
if (!Strings.isNullOrEmpty(GCPUtils.GCS_SUPPORTED_DOC_URL)) {
70+
if (!Strings.isNullOrEmpty(externalDocUrl)) {
6971
if (!errorReason.endsWith(".")) {
7072
errorReason = errorReason + ".";
7173
}

src/main/java/io/cdap/plugin/gcp/gcs/actions/GCSBucketCreate.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ public void run(ActionContext context) throws Exception {
134134
// Add more descriptive error message
135135
String errorReason = String.format("Unable to access or create bucket %s. ", gcsPath.getBucket()) +
136136
"Ensure you entered the correct bucket path and have permissions for it.";
137-
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason);
137+
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason,
138+
GCPUtils.GCS_SUPPORTED_DOC_URL);
138139
}
139140
if (bucket == null) {
140141
GCPUtils.createBucket(storage, gcsPath.getBucket(), config.location, cmekKeyName);
@@ -155,7 +156,7 @@ public void run(ActionContext context) throws Exception {
155156
rollback = true;
156157
String errorReason = "Unable to get GCS filesystem handler.";
157158
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason, ErrorType.UNKNOWN,
158-
true);
159+
true, GCPUtils.GCS_SUPPORTED_DOC_URL);
159160
}
160161
if (!fs.exists(gcsPath)) {
161162
try {
@@ -167,7 +168,7 @@ public void run(ActionContext context) throws Exception {
167168
rollback = true;
168169
String errorReason = String.format("Failed to create path %s.", gcsPath);
169170
throw GCPErrorDetailsProviderUtil.getHttpResponseExceptionDetailsFromChain(e, errorReason,
170-
ErrorType.UNKNOWN, true);
171+
ErrorType.UNKNOWN, true, GCPUtils.GCS_SUPPORTED_DOC_URL);
171172
}
172173
} else {
173174
if (config.failIfExists()) {

0 commit comments

Comments
 (0)