mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-15 06:40:29 +05:30
commit
7bcf791f6a
@ -25,11 +25,23 @@ public class ErrorResponse extends Exception {
|
|||||||
this.content = mapper.writeValueAsBytes(statusObj);
|
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 {
|
public ErrorResponse(int code, Object content) throws JsonProcessingException {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.content = mapper.writeValueAsBytes(content);
|
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() {
|
public int getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package me.kavin.piped.utils;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
|
import me.kavin.piped.utils.resp.InvalidRequestResponse;
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
|
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@ -20,14 +22,22 @@ public class ExceptionHandler {
|
|||||||
if (e.getCause() != null && (e instanceof ExecutionException || e instanceof CompletionException))
|
if (e.getCause() != null && (e instanceof ExecutionException || e instanceof CompletionException))
|
||||||
e = (Exception) e.getCause();
|
e = (Exception) e.getCause();
|
||||||
|
|
||||||
if (!(e instanceof ContentNotAvailableException || e instanceof ErrorResponse)) {
|
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);
|
Sentry.captureException(e);
|
||||||
if (Constants.SENTRY_DSN.isEmpty()) {
|
if (Constants.SENTRY_DSN.isEmpty()) {
|
||||||
if (path != null)
|
if (path != null)
|
||||||
System.err.println("An error occoured in the path: " + path);
|
System.err.println("An error occoured in the path: " + path);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import me.kavin.piped.consts.Constants;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static me.kavin.piped.consts.Constants.mapper;
|
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 class RydHelper {
|
||||||
public static double getDislikeRating(String videoId) throws IOException {
|
public static double getDislikeRating(String videoId) throws IOException {
|
||||||
@ -14,9 +14,15 @@ public class RydHelper {
|
|||||||
if (Constants.DISABLE_RYD)
|
if (Constants.DISABLE_RYD)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
var value = mapper.readTree(sendGet(Constants.RYD_PROXY_URL + "/votes/" + videoId))
|
try (var resp = sendGetRaw(Constants.RYD_PROXY_URL + "/votes/" + videoId)) {
|
||||||
.get("rating");
|
|
||||||
|
|
||||||
return value == null ? -1 : value.asDouble(-1);
|
if (!resp.isSuccessful())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return mapper.readTree(resp.body().byteStream())
|
||||||
|
.path("rating")
|
||||||
|
.asDouble(-1);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user