From dce23a27e57fb716ee56f475659259322779a655 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Tue, 26 Apr 2022 20:06:31 +0200 Subject: [PATCH] De-deduplicate and improve exception message --- .../invidious/InvidiousParsingHelper.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java index 63830ee242..b616b0f45a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java @@ -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();