001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.http.commons.exceptionhandlers;
007
008import static javax.ws.rs.core.Response.status;
009import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
010import static org.slf4j.LoggerFactory.getLogger;
011
012import javax.ws.rs.core.Response;
013import javax.ws.rs.core.Response.Status;
014import javax.ws.rs.ext.ExceptionMapper;
015import javax.ws.rs.ext.Provider;
016
017import org.fcrepo.kernel.api.exception.TransactionRuntimeException;
018import org.slf4j.Logger;
019
020/**
021 * Mapper for transaction exceptions
022 *
023 * @author bbpennel
024 */
025@Provider
026public class TransactionRuntimeExceptionMapper
027        implements ExceptionMapper<TransactionRuntimeException>, ExceptionDebugLogging {
028
029    private static final Logger LOGGER = getLogger(TransactionRuntimeExceptionMapper.class);
030
031    @Override
032    public Response toResponse(final TransactionRuntimeException exception) {
033        debugException(this, exception, LOGGER);
034
035        return status(Status.CONFLICT)
036                .entity(exception.getMessage())
037                .type(TEXT_PLAIN_WITH_CHARSET)
038                .build();
039    }
040
041}