Skip to content

Commit 470d82e

Browse files
authored
new exception type addition (#54)
1 parent fc562ce commit 470d82e

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2011 chargebee.com
3+
* All Rights Reserved.
4+
*/
5+
6+
package com.chargebee.exceptions;
7+
8+
import com.chargebee.APIException;
9+
import org.json.*;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
14+
public class UbbBatchIngestionInvalidRequestException extends APIException{
15+
public final String batchId;
16+
public final JSONArray failedEvents;
17+
public UbbBatchIngestionInvalidRequestException(int httpStatusCode, String message, JSONObject jsonObj, Map<String, List<String>> headers) {
18+
super(httpStatusCode, message, jsonObj);
19+
this.batchId=jsonObj.optString("batch_id");
20+
this.failedEvents=jsonObj.optJSONArray("failed_events");
21+
}
22+
}

src/main/java/com/chargebee/internal/HttpUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ private static void logRetry(int attempt, int statusCode, int delayMs, boolean e
213213

214214
private static Resp sendRequest(HttpURLConnection conn) throws IOException {
215215
int httpRespCode = conn.getResponseCode();
216+
final String UBB_BATCH_INGESTION_INVALID_REQUEST = "ubb_batch_ingestion_invalid_request";
216217
Map<String, List<String>> responseHeaders = conn.getHeaderFields();
217218
if (httpRespCode == HttpURLConnection.HTTP_NO_CONTENT) {
218219
throw new RuntimeException("Got http_no_content response");
@@ -225,7 +226,10 @@ private static Resp sendRequest(HttpURLConnection conn) throws IOException {
225226
jsonResp.getString("api_error_code");
226227
String type = jsonResp.optString("type");
227228
String exceptionMessage = jsonResp.getString("message");
228-
if (isBatchApi(conn)) {
229+
if (UBB_BATCH_INGESTION_INVALID_REQUEST.equals(type)) {
230+
throw new UbbBatchIngestionInvalidRequestException(httpRespCode, exceptionMessage, jsonResp, responseHeaders);
231+
}
232+
else if (isBatchApi(conn)) {
229233
throw new BatchAPIException(httpRespCode, exceptionMessage, jsonResp, responseHeaders);
230234
} else if ("payment".equals(type)) {
231235
throw new PaymentException(httpRespCode, exceptionMessage, jsonResp, responseHeaders);

0 commit comments

Comments
 (0)