All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.e6tech.elements.common.util.ExceptionMapper Maven / Gradle / Ivy

There is a newer version: 2.7.9
Show newest version
package net.e6tech.elements.common.util;

import java.lang.reflect.InvocationTargetException;

/**
 * Created by futeh.
 */
public interface ExceptionMapper {

    @SuppressWarnings("squid:S135")
    static Throwable unwrap(Throwable throwable) {
        Throwable exception = throwable;
        if (exception instanceof InvocationTargetException) {
            InvocationTargetException ite = (InvocationTargetException) exception;
            if (ite.getTargetException() != null)
                exception = ite.getTargetException();
        }

        while (exception instanceof RuntimeException) {
            Exception runtime = (RuntimeException) exception;
            Throwable th = runtime.getCause();
            if (th == null)
                break;
            if (th == exception)
                break;
            exception = th;
        }

        if (exception instanceof InvocationTargetException) {
            InvocationTargetException ite = (InvocationTargetException) exception;
            if (ite.getTargetException() != null)
                exception = ite.getTargetException();
        }

        return exception;
    }

    Class errorResponseClass();

    R toResponse(Throwable exception);

    default Throwable fromResponse(R response) {
        return null;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy