Merge pull request #418 from TeamPiped/improvements

Small Improvements
This commit is contained in:
Kavin 2022-10-31 12:01:23 +00:00 committed by GitHub
commit 7bcf791f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 10 deletions

View File

@ -25,11 +25,23 @@ public class ErrorResponse extends Exception {
this.content = mapper.writeValueAsBytes(statusObj);
}
public ErrorResponse(IStatusCode statusObj, Throwable throwable) throws JsonProcessingException {
super(throwable);
this.code = statusObj.getStatusCode();
this.content = mapper.writeValueAsBytes(statusObj);
}
public ErrorResponse(int code, Object content) throws JsonProcessingException {
this.code = code;
this.content = mapper.writeValueAsBytes(content);
}
public ErrorResponse(int code, Object content, Throwable throwable) throws JsonProcessingException {
super(throwable);
this.code = code;
this.content = mapper.writeValueAsBytes(content);
}
public int getCode() {
return code;
}

View File

@ -3,8 +3,10 @@ package me.kavin.piped.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.sentry.Sentry;
import me.kavin.piped.consts.Constants;
import me.kavin.piped.utils.resp.InvalidRequestResponse;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
@ -20,13 +22,21 @@ public class ExceptionHandler {
if (e.getCause() != null && (e instanceof ExecutionException || e instanceof CompletionException))
e = (Exception) e.getCause();
if (!(e instanceof ContentNotAvailableException || e instanceof ErrorResponse)) {
Sentry.captureException(e);
if (Constants.SENTRY_DSN.isEmpty()) {
if (path != null)
System.err.println("An error occoured in the path: " + path);
e.printStackTrace();
if (e instanceof ContentNotAvailableException || e instanceof ErrorResponse)
return e;
if ((e instanceof ExtractionException extractionException && extractionException.getMessage().contains("No service can handle the url")))
try {
return new ErrorResponse(new InvalidRequestResponse("Invalid parameter provided, unknown service"), extractionException);
} catch (JsonProcessingException jsonProcessingException) {
throw new RuntimeException(jsonProcessingException);
}
Sentry.captureException(e);
if (Constants.SENTRY_DSN.isEmpty()) {
if (path != null)
System.err.println("An error occoured in the path: " + path);
e.printStackTrace();
}
return e;

View File

@ -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);
}
}
}