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 javax.ws.rs.ClientErrorException;
009import javax.ws.rs.core.Response;
010import javax.ws.rs.ext.ExceptionMapper;
011import javax.ws.rs.ext.Provider;
012
013import org.slf4j.Logger;
014
015import static javax.ws.rs.core.Response.fromResponse;
016import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
017import static org.slf4j.LoggerFactory.getLogger;
018
019/**
020 * @author awoods
021 * @since 11/20/14
022 */
023@Provider
024public class ClientErrorExceptionMapper implements
025        ExceptionMapper<ClientErrorException>, ExceptionDebugLogging {
026
027    private static final Logger LOGGER = getLogger(ClientErrorExceptionMapper.class);
028
029    @Override
030    public Response toResponse(final ClientErrorException e) {
031        debugException(this, e, LOGGER);
032        return fromResponse(e.getResponse()).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build();
033    }
034}