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

net.leanix.dropkit.BusinessLogicExceptionMapper Maven / Gradle / Ivy

There is a newer version: 2.0.10
Show newest version
package net.leanix.dropkit;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import net.leanix.dropkit.responses.BasicResponse;

/**
 *
 * @link http://stackoverflow.com/questions/24573028/dropwizard-custom-exception-for-invalidentityexception
 */
@Provider
public class BusinessLogicExceptionMapper implements ExceptionMapper {

    /**
     * Builds a response. Remark: Should not automatically log its results, otherwise any exception ends up in log file,
     * although business logic exceptions should not end up here
     *
     * @param ex
     * @return
     */
    @Override
    public Response toResponse(BusinessLogicException ex) {
        return Response.status(ex.getStatus())
                .entity(new BasicResponse(ex))
                .type("text/json")
                .build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy