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.
This commit is contained in:
Mauricio Colli 2020-02-29 17:52:12 -03:00 committed by TobiGr
parent fcbc96a86c
commit 3441946bea
1 changed files with 6 additions and 2 deletions

View File

@ -102,16 +102,20 @@ public class DownloaderTestImpl extends Downloader {
return new Response(responseCode, responseMessage, responseHeaders, response.toString());
} catch (Exception e) {
final int responseCode = connection.getResponseCode();
/*
* HTTP 429 == Too Many Request
* Receive from Youtube.com = ReCaptcha challenge request
* See : https://github.com/rg3/youtube-dl/issues/5138
*/
if (connection.getResponseCode() == 429) {
if (responseCode == 429) {
throw new ReCaptchaException("reCaptcha Challenge requested", url);
} else if (responseCode != -1) {
return new Response(responseCode, connection.getResponseMessage(), connection.getHeaderFields(), null);
}
throw new IOException(connection.getResponseCode() + " " + connection.getResponseMessage(), e);
throw new IOException("Error occurred while fetching the content", e);
} finally {
if (outputStream != null) outputStream.close();
if (input != null) input.close();