diff --git a/src/main/java/io/cdap/plugin/http/common/pagination/BaseHttpPaginationIterator.java b/src/main/java/io/cdap/plugin/http/common/pagination/BaseHttpPaginationIterator.java index a3f7eab..8534e7e 100644 --- a/src/main/java/io/cdap/plugin/http/common/pagination/BaseHttpPaginationIterator.java +++ b/src/main/java/io/cdap/plugin/http/common/pagination/BaseHttpPaginationIterator.java @@ -204,7 +204,7 @@ public HttpClient getHttpClient() { BasePage createPageInstance(BaseHttpSourceConfig config, HttpResponse httpResponse, ErrorHandling postRetryStrategy) { return PageFactory.createInstance(config, httpResponse, httpErrorHandler, - !postRetryStrategy.equals(ErrorHandling.SUCCESS)); + !postRetryStrategy.equals(ErrorHandling.SUCCESS)); } public PaginationIteratorState getCurrentState() { diff --git a/src/main/java/io/cdap/plugin/http/common/pagination/page/PageFactory.java b/src/main/java/io/cdap/plugin/http/common/pagination/page/PageFactory.java index cfcbfd7..a45870c 100644 --- a/src/main/java/io/cdap/plugin/http/common/pagination/page/PageFactory.java +++ b/src/main/java/io/cdap/plugin/http/common/pagination/page/PageFactory.java @@ -41,9 +41,17 @@ public static BasePage createInstance(BaseHttpSourceConfig config, HttpResponse switch(config.getFormat()) { case JSON: - return new JsonPage(config, httpResponse); + try { + return new JsonPage(config, httpResponse); + } catch (Exception e) { + throw getProgramFailureExceptionBasedOnStatusCode(httpResponse, "JSON", e); + } case XML: - return new XmlPage(config, httpResponse); + try { + return new XmlPage(config, httpResponse); + } catch (Exception e) { + throw getProgramFailureExceptionBasedOnStatusCode(httpResponse, "XML", e); + } case TSV: try { return new DelimitedPage(config, httpResponse, "\t"); @@ -85,11 +93,11 @@ private static ProgramFailureException getProgramFailureExceptionBasedOnStatusCo String.valueOf(httpResponse.getStatusCode()), HttpErrorDetailsProvider.getSupportedDocumentUrl(), e); } else { - String errorReason = String.format("Failed to read %s page with message: %s", fileFormat, - e.getMessage()); + String errorReason = String.format("Failed to read %s page, %s: %s", fileFormat, + e.getClass().getName(), e.getMessage()); return ErrorUtils.getProgramFailureException( new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorReason, - ErrorType.SYSTEM, true, null); + ErrorType.SYSTEM, true, e); } } } diff --git a/src/main/java/io/cdap/plugin/http/sink/batch/HTTPSinkConfig.java b/src/main/java/io/cdap/plugin/http/sink/batch/HTTPSinkConfig.java index 58c6bf5..0be5a78 100644 --- a/src/main/java/io/cdap/plugin/http/sink/batch/HTTPSinkConfig.java +++ b/src/main/java/io/cdap/plugin/http/sink/batch/HTTPSinkConfig.java @@ -200,13 +200,12 @@ public class HTTPSinkConfig extends BaseHttpConfig { private final Integer readTimeout; public HTTPSinkConfig(String referenceName, String url, String method, Integer batchSize, - @Nullable String delimiterForMessages, String messageFormat, @Nullable String body, - @Nullable String requestHeaders, String charset, - boolean followRedirects, boolean disableSSLValidation, @Nullable String httpErrorsHandling, - String errorHandling, String retryPolicy, @Nullable Long linearRetryInterval, - Long maxRetryDuration, int readTimeout, int connectTimeout, - String oauth2Enabled, String authType, @Nullable String jsonBatchKey, - Boolean writeJsonAsArray) { + @Nullable String delimiterForMessages, String messageFormat, @Nullable String body, + @Nullable String requestHeaders, String charset, boolean followRedirects, + boolean disableSSLValidation, @Nullable String httpErrorsHandling, String errorHandling, + String retryPolicy, @Nullable Long linearRetryInterval, Long maxRetryDuration, + int readTimeout, int connectTimeout, String oauth2Enabled, String authType, + @Nullable String jsonBatchKey, Boolean writeJsonAsArray) { super(referenceName); this.url = url; this.method = method; diff --git a/src/main/java/io/cdap/plugin/http/source/common/RawStringPerLine.java b/src/main/java/io/cdap/plugin/http/source/common/RawStringPerLine.java index 4d3197f..ebaa8c8 100644 --- a/src/main/java/io/cdap/plugin/http/source/common/RawStringPerLine.java +++ b/src/main/java/io/cdap/plugin/http/source/common/RawStringPerLine.java @@ -62,9 +62,13 @@ public void close() { try { bufferedReader.close(); } catch (IOException e) { - String errorMessage = "Unable to close the buffered reader for the http response."; - throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), - errorMessage, errorMessage, ErrorType.SYSTEM, true, null); + String errorReason = "Unable to close the buffered reader for the http response."; + String errorMessage = String.format( + "Unable to close the buffered reader for the http response, %s: %s", + e.getClass().getName(), e.getMessage()); + throw ErrorUtils.getProgramFailureException( + new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, + errorMessage, ErrorType.SYSTEM, false, e); } } } @@ -97,7 +101,7 @@ public boolean hasNext() { "Unable to read line from http page buffer with message: %s", e.getMessage()); throw ErrorUtils.getProgramFailureException( new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, - errorReason, ErrorType.SYSTEM, true, null); + errorReason, ErrorType.SYSTEM, true, e); } } }