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.kernel.api.exception; 008 009import static org.apache.http.HttpStatus.SC_PRECONDITION_FAILED; 010import static org.apache.http.HttpStatus.SC_NOT_MODIFIED; 011 012/** 013 * @author dbernstein 014 * @since Jun 22, 2017 015 */ 016public class PreconditionException extends RepositoryRuntimeException { 017 018 private static final long serialVersionUID = 1L; 019 020 private int httpStatus; 021 022 /** 023 * Ordinary constructor 024 * 025 * @param msg error message 026 * @param httpStatus the http status code 027 */ 028 public PreconditionException(final String msg, final int httpStatus) { 029 super(msg); 030 if (httpStatus != SC_PRECONDITION_FAILED && httpStatus != SC_NOT_MODIFIED) { 031 throw new IllegalArgumentException("Invalid httpStatus (" + httpStatus + 032 "). The http status for PreconditionExceptions must be " + 033 SC_PRECONDITION_FAILED + " or " + SC_NOT_MODIFIED); 034 } 035 this.httpStatus = httpStatus; 036 } 037 038 /** 039 * @return the httpStatus 040 */ 041 public int getHttpStatus() { 042 return httpStatus; 043 } 044}