Skip to content

Commit c0fd067

Browse files
Merge pull request #1477 from data-integrations/CDAP-20931
[CDAP-20931] Add errorCodeType, errorCode & supportedDocURL in exception
2 parents 228ece3 + 02b04b4 commit c0fd067

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

src/main/java/io/cdap/plugin/gcp/bigquery/common/BigQueryErrorDetailsProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.cdap.plugin.gcp.bigquery.common;
1818

1919
import io.cdap.plugin.gcp.common.GCPErrorDetailsProvider;
20+
import io.cdap.plugin.gcp.common.GCPUtils;
2021

2122
/**
2223
* A custom ErrorDetailsProvider for BigQuery plugins.
@@ -25,6 +26,6 @@ public class BigQueryErrorDetailsProvider extends GCPErrorDetailsProvider {
2526

2627
@Override
2728
protected String getExternalDocumentationLink() {
28-
return "https://cloud.google.com/bigquery/docs/error-messages";
29+
return GCPUtils.BQ_SUPPORTED_DOC_URL;
2930
}
3031
}

src/main/java/io/cdap/plugin/gcp/bigquery/sink/BigQuerySinkUtils.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.google.gson.Gson;
3737
import io.cdap.cdap.api.data.schema.Schema;
3838
import io.cdap.cdap.api.exception.ErrorCategory;
39+
import io.cdap.cdap.api.exception.ErrorCodeType;
3940
import io.cdap.cdap.api.exception.ErrorType;
4041
import io.cdap.cdap.api.exception.ErrorUtils;
4142
import io.cdap.cdap.etl.api.FailureCollector;
@@ -196,10 +197,12 @@ private static void createDataset(BigQuery bigQuery, DatasetId dataset, @Nullabl
196197
// This most likely means multiple stages in the same pipeline are trying to create the same dataset.
197198
// Ignore this and move on, since all that matters is that the dataset exists.
198199
ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(e.getCode());
199-
String errorReason = String.format("%s %s %s", e.getCode(), e.getMessage(), pair.getCorrectiveAction());
200+
String errorReason = String.format("%s %s %s For more details, see %s", e.getCode(),
201+
e.getMessage(), pair.getCorrectiveAction(), GCPUtils.BQ_SUPPORTED_DOC_URL);
200202
throw ErrorUtils.getProgramFailureException(
201203
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage.get(),
202-
pair.getErrorType(), true, e);
204+
pair.getErrorType(), true, ErrorCodeType.HTTP, String.valueOf(e.getCode()),
205+
GCPUtils.BQ_SUPPORTED_DOC_URL, e);
203206
}
204207
}
205208
}
@@ -244,10 +247,12 @@ private static void createBucket(Storage storage, String bucket, @Nullable Strin
244247
// This most likely means multiple stages in the same pipeline are trying to create the same dataset.
245248
// Ignore this and move on, since all that matters is that the dataset exists.
246249
ErrorUtils.ActionErrorPair pair = ErrorUtils.getActionErrorByStatusCode(e.getCode());
247-
String errorReason = String.format("%s %s %s", e.getCode(), e.getMessage(), pair.getCorrectiveAction());
250+
String errorReason = String.format("%s %s %s For more details, see %s", e.getCode(),
251+
e.getMessage(), pair.getCorrectiveAction(), GCPUtils.GCS_SUPPORTED_DOC_URL);
248252
throw ErrorUtils.getProgramFailureException(
249253
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage.get(),
250-
pair.getErrorType(), true, e);
254+
pair.getErrorType(), true, ErrorCodeType.HTTP, String.valueOf(e.getCode()),
255+
GCPUtils.GCS_SUPPORTED_DOC_URL, e);
251256
}
252257
}
253258
}

src/main/java/io/cdap/plugin/gcp/bigquery/source/BigQuerySourceUtils.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.cloud.storage.Storage;
2727
import com.google.cloud.storage.StorageException;
2828
import io.cdap.cdap.api.exception.ErrorCategory;
29+
import io.cdap.cdap.api.exception.ErrorCodeType;
2930
import io.cdap.cdap.api.exception.ErrorType;
3031
import io.cdap.cdap.api.exception.ErrorUtils;
3132
import io.cdap.plugin.gcp.bigquery.connector.BigQueryConnectorConfig;
@@ -96,12 +97,14 @@ public static String getOrCreateBucket(Configuration configuration,
9697
// Ignore this and move on, since all that matters is that the bucket exists.
9798
return bucket;
9899
}
99-
String errorMessage = String.format("Unable to create Cloud Storage bucket '%s' in the same " +
100-
"location ('%s') as BigQuery dataset '%s'. " + "Please use a bucket " +
101-
"that is in the same location as the dataset.",
102-
bucket, dataset.getLocation(), dataset.getDatasetId().getDataset());
100+
String errorMessage = String.format("Unable to create Cloud Storage bucket '%s' in the same "
101+
+ "location ('%s') as BigQuery dataset '%s'. " + "Please use a bucket "
102+
+ "that is in the same location as the dataset. For more details, see %s",
103+
bucket, dataset.getLocation(), dataset.getDatasetId().getDataset(),
104+
GCPUtils.GCS_SUPPORTED_DOC_URL);
103105
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN),
104-
errorMessage, e.getMessage(), ErrorType.USER, true, e);
106+
errorMessage, e.getMessage(), ErrorType.USER, true, ErrorCodeType.HTTP,
107+
String.valueOf(e.getCode()), GCPUtils.GCS_SUPPORTED_DOC_URL, e);
105108
}
106109
}
107110

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public class GCPUtils {
7979
"https://www.googleapis.com/auth/bigquery");
8080
public static final String FQN_RESERVED_CHARACTERS_PATTERN = ".*[.:` \t\n].*";
8181
public static final int MILLISECONDS_MULTIPLIER = 1000;
82+
public static final String GCS_SUPPORTED_DOC_URL = "https://cloud.google.com/storage/docs/json_api/v1/status-codes";
83+
public static final String BQ_SUPPORTED_DOC_URL = "https://cloud.google.com/bigquery/docs/error-messages";
8284

8385
/**
8486
* Load a service account from the local file system.

src/main/java/io/cdap/plugin/gcp/gcs/GCSErrorDetailsProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.cdap.plugin.gcp.gcs;
1818

1919
import io.cdap.plugin.gcp.common.GCPErrorDetailsProvider;
20+
import io.cdap.plugin.gcp.common.GCPUtils;
2021

2122
/**
2223
* A custom ErrorDetailsProvider for GCS plugins.
@@ -25,6 +26,6 @@ public class GCSErrorDetailsProvider extends GCPErrorDetailsProvider {
2526

2627
@Override
2728
protected String getExternalDocumentationLink() {
28-
return "https://cloud.google.com/storage/docs/json_api/v1/status-codes";
29+
return GCPUtils.GCS_SUPPORTED_DOC_URL;
2930
}
3031
}

0 commit comments

Comments
 (0)