Skip to content

Commit

Permalink
De-deduplicate and improve exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
litetex committed May 7, 2022
1 parent ec5598f commit dce23a2
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,19 @@ public static String getValidResponseBody(
final Response response,
final String apiUrl
) throws ExtractionException {
if (response.responseCode() == 404) {
throw new ContentNotAvailableException("Could not get page " + apiUrl
+ " (HTTP " + response.responseCode() + " : " + response.responseMessage());
} else if (response.responseCode() >= 400) {
throw new ExtractionException("Could not get page " + apiUrl
+ " (HTTP " + response.responseCode() + " : " + response.responseMessage());
if (response.responseCode() >= 400) {
final String trimmedBody = response.responseBody().length() > 100
? response.responseBody().substring(0, 98) + "..."
: response.responseBody();
final String message = "Could not get page " + apiUrl
+ " [code=" + response.responseCode()
+ ",message=" + response.responseMessage()
+ ",body=" + trimmedBody
+ "]";
if (response.responseCode() == 404) {
throw new ContentNotAvailableException(message);
}
throw new ExtractionException(message);
}

return response.responseBody();
Expand Down

0 comments on commit dce23a2

Please sign in to comment.