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 javax.ws.rs.core.Response.Status.BAD_REQUEST;
010import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
011import static org.slf4j.LoggerFactory.getLogger;
012
013import javax.ws.rs.core.Response;
014import javax.ws.rs.ext.ExceptionMapper;
015import javax.ws.rs.ext.Provider;
016
017import org.fcrepo.kernel.api.exception.FedoraInvalidNamespaceException;
018
019import org.slf4j.Logger;
020
021/**
022 * For invalid namespace exceptions on CRUD actions for nodes/datastreams
023 *
024 * @author whikloj
025 * @since September 12, 2014
026 */
027@Provider
028public class FedoraInvalidNamespaceExceptionMapper implements
029        ExceptionMapper<FedoraInvalidNamespaceException>, ExceptionDebugLogging {
030
031    private static final Logger LOGGER = getLogger(FedoraInvalidNamespaceExceptionMapper.class);
032
033    @Override
034    public Response toResponse(final FedoraInvalidNamespaceException e) {
035        LOGGER.error("NamespaceExceptionMapper caught an exception: {}", e.getMessage());
036        debugException(this, e, LOGGER);
037        return status(BAD_REQUEST).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build();
038    }
039
040}