Skip to content

Commit 3441946

Browse files
mauriciocolliTobiGr
authored andcommitted
Make test downloader return a response instead of throwing an exception
The test implementation was throwing an exception instead of just returning the response and letting the caller handle it.
1 parent fcbc96a commit 3441946

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,20 @@ public Response execute(@Nonnull Request request) throws IOException, ReCaptchaE
102102

103103
return new Response(responseCode, responseMessage, responseHeaders, response.toString());
104104
} catch (Exception e) {
105+
final int responseCode = connection.getResponseCode();
106+
105107
/*
106108
* HTTP 429 == Too Many Request
107109
* Receive from Youtube.com = ReCaptcha challenge request
108110
* See : https://github.com/rg3/youtube-dl/issues/5138
109111
*/
110-
if (connection.getResponseCode() == 429) {
112+
if (responseCode == 429) {
111113
throw new ReCaptchaException("reCaptcha Challenge requested", url);
114+
} else if (responseCode != -1) {
115+
return new Response(responseCode, connection.getResponseMessage(), connection.getHeaderFields(), null);
112116
}
113117

114-
throw new IOException(connection.getResponseCode() + " " + connection.getResponseMessage(), e);
118+
throw new IOException("Error occurred while fetching the content", e);
115119
} finally {
116120
if (outputStream != null) outputStream.close();
117121
if (input != null) input.close();

0 commit comments

Comments
 (0)