Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-CloudSufi committed Jan 27, 2025
1 parent 38068e4 commit 4fa479c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
}
13 changes: 6 additions & 7 deletions src/main/java/io/cdap/plugin/http/sink/batch/HTTPSinkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 4fa479c

Please sign in to comment.