From 3441946bea9c172a4c96dd6deae450cecab875a4 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Sat, 29 Feb 2020 17:52:12 -0300 Subject: [PATCH] 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. --- .../test/java/org/schabi/newpipe/DownloaderTestImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java b/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java index e524ac8d..8d7a3437 100644 --- a/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java +++ b/extractor/src/test/java/org/schabi/newpipe/DownloaderTestImpl.java @@ -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();