diff --git a/src/main/java/com/chargebee/exceptions/UbbBatchIngestionInvalidRequestException.java b/src/main/java/com/chargebee/exceptions/UbbBatchIngestionInvalidRequestException.java new file mode 100644 index 00000000..564e2455 --- /dev/null +++ b/src/main/java/com/chargebee/exceptions/UbbBatchIngestionInvalidRequestException.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2011 chargebee.com + * All Rights Reserved. + */ + +package com.chargebee.exceptions; + +import com.chargebee.APIException; +import org.json.*; +import java.util.List; +import java.util.Map; + + +public class UbbBatchIngestionInvalidRequestException extends APIException{ + public final String batchId; + public final JSONArray failedEvents; + public UbbBatchIngestionInvalidRequestException(int httpStatusCode, String message, JSONObject jsonObj, Map> headers) { + super(httpStatusCode, message, jsonObj); + this.batchId=jsonObj.optString("batch_id"); + this.failedEvents=jsonObj.optJSONArray("failed_events"); + } +} \ No newline at end of file diff --git a/src/main/java/com/chargebee/internal/HttpUtil.java b/src/main/java/com/chargebee/internal/HttpUtil.java index 5c8b2e20..d935dcc2 100644 --- a/src/main/java/com/chargebee/internal/HttpUtil.java +++ b/src/main/java/com/chargebee/internal/HttpUtil.java @@ -213,6 +213,7 @@ private static void logRetry(int attempt, int statusCode, int delayMs, boolean e private static Resp sendRequest(HttpURLConnection conn) throws IOException { int httpRespCode = conn.getResponseCode(); + final String UBB_BATCH_INGESTION_INVALID_REQUEST = "ubb_batch_ingestion_invalid_request"; Map> responseHeaders = conn.getHeaderFields(); if (httpRespCode == HttpURLConnection.HTTP_NO_CONTENT) { throw new RuntimeException("Got http_no_content response"); @@ -225,7 +226,10 @@ private static Resp sendRequest(HttpURLConnection conn) throws IOException { jsonResp.getString("api_error_code"); String type = jsonResp.optString("type"); String exceptionMessage = jsonResp.getString("message"); - if (isBatchApi(conn)) { + if (UBB_BATCH_INGESTION_INVALID_REQUEST.equals(type)) { + throw new UbbBatchIngestionInvalidRequestException(httpRespCode, exceptionMessage, jsonResp, responseHeaders); + } + else if (isBatchApi(conn)) { throw new BatchAPIException(httpRespCode, exceptionMessage, jsonResp, responseHeaders); } else if ("payment".equals(type)) { throw new PaymentException(httpRespCode, exceptionMessage, jsonResp, responseHeaders);