From e629121c252a44146def9991b145e85ed3977053 Mon Sep 17 00:00:00 2001 From: FireMaskterK <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 8 Nov 2021 20:35:02 +0000 Subject: [PATCH] Log path only when exception is logged. --- src/main/java/me/kavin/piped/ServerLauncher.java | 3 +-- src/main/java/me/kavin/piped/utils/ExceptionHandler.java | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index 8128673..af95d49 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -301,8 +301,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { private @NotNull HttpResponse getErrorResponse(Exception e, String path) { - System.err.println("An error occoured in the path: " + path); - e = ExceptionHandler.handle(e); + e = ExceptionHandler.handle(e, path); try { return getJsonResponse(500, Constants.mapper diff --git a/src/main/java/me/kavin/piped/utils/ExceptionHandler.java b/src/main/java/me/kavin/piped/utils/ExceptionHandler.java index 6b430de..cca316c 100644 --- a/src/main/java/me/kavin/piped/utils/ExceptionHandler.java +++ b/src/main/java/me/kavin/piped/utils/ExceptionHandler.java @@ -10,13 +10,20 @@ 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) { if (e.getCause() != null && (e instanceof ExecutionException || e instanceof CompletionException)) e = (Exception) e.getCause(); if (!(e instanceof AgeRestrictedContentException || e instanceof ContentNotAvailableException - || e instanceof GeographicRestrictionException)) + || e instanceof GeographicRestrictionException)) { + if (path != null) + System.err.println("An error occoured in the path: " + path); e.printStackTrace(); + } return e; }