From afd213b4c8f5c54091c111b1c7de852bf47bf048 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 31 Oct 2022 11:49:22 +0000 Subject: [PATCH] Handle potential bad responses for RYD. --- src/main/java/me/kavin/piped/utils/RydHelper.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/kavin/piped/utils/RydHelper.java b/src/main/java/me/kavin/piped/utils/RydHelper.java index dfa4375..0579f0a 100644 --- a/src/main/java/me/kavin/piped/utils/RydHelper.java +++ b/src/main/java/me/kavin/piped/utils/RydHelper.java @@ -6,7 +6,7 @@ import me.kavin.piped.consts.Constants; import java.io.IOException; import static me.kavin.piped.consts.Constants.mapper; -import static me.kavin.piped.utils.RequestUtils.sendGet; +import static me.kavin.piped.utils.RequestUtils.sendGetRaw; public class RydHelper { public static double getDislikeRating(String videoId) throws IOException { @@ -14,9 +14,15 @@ public class RydHelper { if (Constants.DISABLE_RYD) return -1; - var value = mapper.readTree(sendGet(Constants.RYD_PROXY_URL + "/votes/" + videoId)) - .get("rating"); + try (var resp = sendGetRaw(Constants.RYD_PROXY_URL + "/votes/" + videoId)) { - return value == null ? -1 : value.asDouble(-1); + if (!resp.isSuccessful()) + return -1; + + return mapper.readTree(resp.body().byteStream()) + .path("rating") + .asDouble(-1); + + } } }