Skip to content

Commit d865612

Browse files
committed
Added an option to change object mapper
1 parent d370782 commit d865612

File tree

2 files changed

+5
-78
lines changed

2 files changed

+5
-78
lines changed

src/main/java/com/taboola/rest/api/internal/SynchronousCallAdapterFactory.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.taboola.rest.api.internal;
22

33
import com.taboola.rest.api.exceptions.RestAPIConnectivityException;
4+
import com.taboola.rest.api.exceptions.RestAPIRequestException;
45
import com.taboola.rest.api.exceptions.factories.ExceptionFactory;
56

67
import org.apache.logging.log4j.LogManager;
@@ -64,7 +65,8 @@ public Object adapt(Call<Object> call) {
6465
exceptionFactory.handleAndThrowUnauthorizedException(safeCreateCauseException(response));
6566

6667
} else if(responseCode >= BAD_REQUEST_HTTP_STATUS_CODE && responseCode < INTERNAL_SERVER_ERROR_HTTP_STATUS_CODE) {
67-
exceptionFactory.handleAndThrowRequestException(responseCode, safeGetErrorPayloadBytes(response), normalizeErrorMsg(response.message()));
68+
String message = normalizeErrorMsg(response.message());
69+
exceptionFactory.handleAndThrowRequestException(responseCode, safeGetErrorPayloadBytes(response, message, responseCode), message);
6870
}
6971

7072
exceptionFactory.handleAndThrowConnectivityException(safeCreateCauseException(response), responseCode);
@@ -84,12 +86,12 @@ public Object adapt(Call<Object> call) {
8486
};
8587
}
8688

87-
private byte[] safeGetErrorPayloadBytes(Response<Object> response) throws IOException {
89+
private byte[] safeGetErrorPayloadBytes(Response<Object> response, String message, int responseCode) throws IOException {
8890
try {
8991
return response.errorBody().bytes();
9092
} catch(Throwable t) {
9193
logger.warn("Failed to extract byte[] from response error body", t);
92-
throw new RestAPIConnectivityException();
94+
throw new RestAPIRequestException("message: %s, responseCode: %s", message, responseCode);
9395
}
9496
}
9597

src/main/java/com/taboola/rest/api/model/APIError.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)