Piped-Backend/src/main/java/me/kavin/piped/utils/ExceptionHandler.java

31 lines
1 KiB
Java
Raw Normal View History

2021-09-09 18:49:46 +00:00
package me.kavin.piped.utils;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException;
public class ExceptionHandler {
public static Exception handle(Exception e) {
return handle(e, null);
}
public static Exception handle(Exception e, String path) {
2021-09-09 18:49:46 +00:00
if (e.getCause() != null && (e instanceof ExecutionException || e instanceof CompletionException))
e = (Exception) e.getCause();
if (!(e instanceof AgeRestrictedContentException || e instanceof ContentNotAvailableException
|| e instanceof GeographicRestrictionException)) {
if (path != null)
System.err.println("An error occoured in the path: " + path);
2021-09-09 18:49:46 +00:00
e.printStackTrace();
}
2021-09-09 18:49:46 +00:00
return e;
}
}