001package ca.uhn.fhir.rest.server.exceptions; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2017 University Health Network 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; 024 025import ca.uhn.fhir.context.FhirContext; 026import ca.uhn.fhir.rest.api.Constants; 027import ca.uhn.fhir.util.CoverageIgnore; 028import ca.uhn.fhir.util.OperationOutcomeUtil; 029 030/** 031 * Represents an <b>HTTP 422 Unprocessable Entity</b> response, which means that a resource was rejected by the server because it "violated applicable FHIR profiles or server business rules". 032 * 033 * <p> 034 * This exception will generally contain an {@link IBaseOperationOutcome} instance which details the failure. 035 * </p> 036 * 037 * @see InvalidRequestException Which corresponds to an <b>HTTP 400 Bad Request</b> failure 038 */ 039@CoverageIgnore 040public class UnprocessableEntityException extends BaseServerResponseException { 041 042 private static final String DEFAULT_MESSAGE = "Unprocessable Entity"; 043 private static final long serialVersionUID = 1L; 044 public static final int STATUS_CODE = Constants.STATUS_HTTP_422_UNPROCESSABLE_ENTITY; 045 046 /** 047 * Constructor 048 * 049 * @param theMessage 050 * The message to add to the status line 051 * @param theOperationOutcome The {@link IBaseOperationOutcome} resource to return to the client 052 */ 053 public UnprocessableEntityException(String theMessage, IBaseOperationOutcome theOperationOutcome) { 054 super(STATUS_CODE, theMessage, theOperationOutcome); 055 } 056 057 058 /** 059 * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response 060 * 061 * @deprecated Use constructor with FhirContext argument 062 */ 063 @Deprecated 064 public UnprocessableEntityException(IBaseOperationOutcome theOperationOutcome) { 065 super(STATUS_CODE, DEFAULT_MESSAGE, theOperationOutcome); 066 } 067 068 /** 069 * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response 070 */ 071 public UnprocessableEntityException(FhirContext theCtx, IBaseOperationOutcome theOperationOutcome) { 072 super(STATUS_CODE, OperationOutcomeUtil.getFirstIssueDetails(theCtx, theOperationOutcome), theOperationOutcome); 073 } 074 075 /** 076 * Constructor which accepts a String describing the issue. This string will be translated into an {@link IBaseOperationOutcome} resource which will be supplied in the response. 077 */ 078 public UnprocessableEntityException(String theMessage) { 079 super(STATUS_CODE, theMessage); 080 } 081 082 /** 083 * Constructor which accepts an array of Strings describing the issue. This strings will be translated into an {@link IBaseOperationOutcome} resource which will be supplied in the response. 084 */ 085 public UnprocessableEntityException(String... theMessage) { 086 super(STATUS_CODE, theMessage); 087 } 088 089}