Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class HttpException extends CrowdinApiException {

public Error error;
public String httpResponse;

@Data
public static class Error {
Expand All @@ -18,11 +19,12 @@ public static class Error {

}

public static HttpException fromMessage(String message) {
public static HttpException fromMessage(String message, String httpResponse) {
var resp = new HttpException();
var error = new Error();
error.setMessage(message);
resp.setError(error);
resp.setHttpResponse(httpResponse);
return resp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private <T, V> T request(String url,
Class<T> clazz,
String method) throws HttpException, HttpBadRequestException {
HttpUriRequest request = this.buildRequest(method, url, data, config);
String httpResponse = null;
try (CloseableHttpResponse response = httpClient.execute(request)) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode < 200 || statusCode >= 300) {
Expand All @@ -134,9 +135,10 @@ private <T, V> T request(String url,
if (Void.class.equals(clazz)) {
return null;
}
return this.jsonTransformer.parse(this.toString(response.getEntity()), clazz);
httpResponse = this.toString(response.getEntity());
return this.jsonTransformer.parse(httpResponse, clazz);
} catch (IOException e) {
throw HttpException.fromMessage(e.getMessage());
throw HttpException.fromMessage(e.getMessage(), httpResponse);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public CrowdinApiException deserialize(JsonParser p, DeserializationContext ctxt
} else if (treeNode.get("error") != null) {
return this.objectMapper.treeToValue(treeNode, HttpException.class);
} else {
return HttpException.fromMessage(treeNode.toString());
return HttpException.fromMessage(treeNode.toString(), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class HttpExceptionTest {

@Test
public void httpExceptionFromTest() {
HttpException message = HttpException.fromMessage("Exception message!");
HttpException message = HttpException.fromMessage("Exception message!", null);
assertEquals(message.getError().getMessage(), "Exception message!");
}
}
Loading