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 */ 006 007package org.fcrepo.http.commons.exceptionhandlers; 008 009import org.fcrepo.kernel.api.exception.InsufficientStorageException; 010import org.slf4j.Logger; 011 012import javax.ws.rs.core.Response; 013import javax.ws.rs.ext.ExceptionMapper; 014import javax.ws.rs.ext.Provider; 015 016import static javax.ws.rs.core.Response.status; 017import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET; 018import static org.slf4j.LoggerFactory.getLogger; 019 020/** 021 * Translate InsufficientStorageException errors into HTTP error codes 022 * 023 * @author Daniel Bernstein 024 * @since Oct 7, 2016 025 */ 026@Provider 027public class InsufficientStorageExceptionMapper implements 028 ExceptionMapper<InsufficientStorageException>, ExceptionDebugLogging { 029 030 private static final Logger LOGGER = 031 getLogger(InsufficientStorageException.class); 032 033 public static final int INSUFFICIENT_STORAGE_HTTP_CODE = 507; 034 035 @Override 036 public Response toResponse(final InsufficientStorageException e) { 037 LOGGER.error("Insufficient storage", e); 038 return status(INSUFFICIENT_STORAGE_HTTP_CODE).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); 039 } 040}