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

com.bendb.dropwizard.jooq.jersey.LoggingDataAccessExceptionMapper Maven / Gradle / Ivy

There is a newer version: 3.0.0-0
Show newest version
package com.bendb.dropwizard.jooq.jersey;

import com.google.common.annotations.VisibleForTesting;
import io.dropwizard.jersey.errors.LoggingExceptionMapper;
import org.jooq.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.ext.Provider;
import java.sql.SQLException;

@Provider
public class LoggingDataAccessExceptionMapper extends LoggingExceptionMapper {
    private static Logger logger = LoggerFactory.getLogger(LoggingDataAccessExceptionMapper.class);

    @Override
    protected void logException(long id, DataAccessException exception) {
        final Throwable cause = exception.getCause();
        if (cause instanceof SQLException) {
            for (Throwable throwable : (SQLException) cause) {
                logger.error(formatLogMessage(id, throwable), throwable);
            }
        } else {
            logger.error(formatLogMessage(id, exception), exception);
        }
    }

    @VisibleForTesting
    static void setLogger(Logger logger) {
        LoggingDataAccessExceptionMapper.logger = logger;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy