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.ext.ExceptionMapper; 014import javax.ws.rs.ext.Provider; 015 016import org.fcrepo.kernel.api.exception.PreconditionException; 017 018import org.slf4j.Logger; 019 020/** 021 * Maps PreconditionException to an appropriate http response. 022 * @author Daniel Bernstein 023 * @since Jun 22, 2017 024 */ 025@Provider 026public class PreconditionExceptionMapper implements 027 ExceptionMapper<PreconditionException>, ExceptionDebugLogging { 028 029 private static final Logger LOGGER = 030 getLogger(PreconditionExceptionMapper.class); 031 032 @Override 033 public Response toResponse(final PreconditionException e) { 034 debugException(this, e, LOGGER); 035 return status(e.getHttpStatus()).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); 036 } 037}