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 org.slf4j.Logger; 009 010import javax.ws.rs.ServerErrorException; 011import javax.ws.rs.core.Response; 012import javax.ws.rs.ext.ExceptionMapper; 013import javax.ws.rs.ext.Provider; 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 ServerErrorExceptionMapper implements 025 ExceptionMapper<ServerErrorException>, ExceptionDebugLogging { 026 027 private static final Logger LOGGER = 028 getLogger(ServerErrorExceptionMapper.class); 029 030 @Override 031 public Response toResponse(final ServerErrorException e) { 032 LOGGER.warn("Server error", e); 033 return fromResponse(e.getResponse()).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); 034 } 035}