Skip to content

Commit dce23a2

Browse files
committed
De-deduplicate and improve exception message
1 parent ec5598f commit dce23a2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,19 @@ public static String getValidResponseBody(
6161
final Response response,
6262
final String apiUrl
6363
) throws ExtractionException {
64-
if (response.responseCode() == 404) {
65-
throw new ContentNotAvailableException("Could not get page " + apiUrl
66-
+ " (HTTP " + response.responseCode() + " : " + response.responseMessage());
67-
} else if (response.responseCode() >= 400) {
68-
throw new ExtractionException("Could not get page " + apiUrl
69-
+ " (HTTP " + response.responseCode() + " : " + response.responseMessage());
64+
if (response.responseCode() >= 400) {
65+
final String trimmedBody = response.responseBody().length() > 100
66+
? response.responseBody().substring(0, 98) + "..."
67+
: response.responseBody();
68+
final String message = "Could not get page " + apiUrl
69+
+ " [code=" + response.responseCode()
70+
+ ",message=" + response.responseMessage()
71+
+ ",body=" + trimmedBody
72+
+ "]";
73+
if (response.responseCode() == 404) {
74+
throw new ContentNotAvailableException(message);
75+
}
76+
throw new ExtractionException(message);
7077
}
7178

7279
return response.responseBody();

0 commit comments

Comments
 (0)