Replaced interface in WebExceptionLogger with a more generic one

This commit is contained in:
Rsl1122 2018-05-29 11:03:16 +03:00
parent 24bab50367
commit 3824741b5d
2 changed files with 17 additions and 8 deletions

View File

@ -5,6 +5,7 @@
package com.djrapitops.plan.system.info.connection; package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.utilities.java.ThrowingVoidFunction;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,9 +20,9 @@ import java.util.Map;
*/ */
public class WebExceptionLogger { public class WebExceptionLogger {
public static void logIfOccurs(Class c, ExceptionLoggingAction action) { public static void logIfOccurs(Class c, ThrowingVoidFunction<WebException> function) {
try { try {
action.performAction(); function.apply();
} catch (ConnectionFailException e) { } catch (ConnectionFailException e) {
if (shouldLog(e)) { if (shouldLog(e)) {
Log.warn(e.getMessage()); Log.warn(e.getMessage());
@ -62,10 +63,4 @@ public class WebExceptionLogger {
return null; return null;
} }
public interface ExceptionLoggingAction {
void performAction() throws WebException;
}
} }

View File

@ -0,0 +1,14 @@
package com.djrapitops.plan.utilities.java;
/**
* Functional interface that performs an operation that might throw an exception.
* <p>
* Follows naming scheme of Java 8 functional interfaces.
*
* @author Rsl1122
*/
public interface ThrowingVoidFunction<T extends Throwable> {
void apply() throws T;
}