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

com.cvent.dropwizard.mybatis.exceptionMappers.PersistenceExceptionMapper Maven / Gradle / Ivy

Go to download

An open source bridge layer so that you can use mybatis with dropwizard + other useful utility methods often used within an enterprise.

There is a newer version: 4.0.4
Show newest version
package com.cvent.dropwizard.mybatis.exceptionMappers;

import org.apache.ibatis.exceptions.PersistenceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import java.util.HashMap;
import java.util.Map;

/**
 * Mapper to trap unhandled SQL exceptions and prevent the query text from leaking into response messages
 */
public class PersistenceExceptionMapper implements ExceptionMapper {

    private static final Logger LOG = LoggerFactory.getLogger(PersistenceExceptionMapper.class);

    private static final Map RESPONSE_MESSAGE = new HashMap<>();

    static {
        RESPONSE_MESSAGE.put("message", "Internal error");
    }

    @Override
    public Response toResponse(PersistenceException exception) {
        LOG.error("Unhandled SQL Exception", exception);

        return Response
                .status(Response.Status.INTERNAL_SERVER_ERROR)
                .entity(RESPONSE_MESSAGE)
                .build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy