View Javadoc
1   package ca.uhn.fhir.rest.server.exceptions;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.context.FhirContext;
24  import ca.uhn.fhir.rest.api.Constants;
25  import ca.uhn.fhir.util.CoverageIgnore;
26  import ca.uhn.fhir.util.OperationOutcomeUtil;
27  import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
28  
29  /**
30   * 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".
31   *
32   * <p>
33   * This exception will generally contain an {@link IBaseOperationOutcome} instance which details the failure.
34   * </p>
35   *
36   * @see InvalidRequestException Which corresponds to an <b>HTTP 400 Bad Request</b> failure
37   */
38  @CoverageIgnore
39  public class UnprocessableEntityException extends BaseServerResponseException {
40  
41  	public static final int STATUS_CODE = Constants.STATUS_HTTP_422_UNPROCESSABLE_ENTITY;
42  	private static final String DEFAULT_MESSAGE = "Unprocessable Entity";
43  	private static final long serialVersionUID = 1L;
44  
45  	/**
46  	 * Constructor
47  	 *
48  	 * @param theMessage          The message to add to the status line
49  	 * @param theOperationOutcome The {@link IBaseOperationOutcome} resource to return to the client
50  	 */
51  	public UnprocessableEntityException(String theMessage, IBaseOperationOutcome theOperationOutcome) {
52  		super(STATUS_CODE, theMessage, theOperationOutcome);
53  	}
54  
55  
56  	/**
57  	 * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response
58  	 *
59  	 * @deprecated Use constructor with FhirContext argument
60  	 */
61  	@Deprecated
62  	public UnprocessableEntityException(IBaseOperationOutcome theOperationOutcome) {
63  		super(STATUS_CODE, DEFAULT_MESSAGE, theOperationOutcome);
64  	}
65  
66  	/**
67  	 * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response
68  	 */
69  	public UnprocessableEntityException(FhirContext theCtx, IBaseOperationOutcome theOperationOutcome) {
70  		super(STATUS_CODE, OperationOutcomeUtil.getFirstIssueDetails(theCtx, theOperationOutcome), theOperationOutcome);
71  	}
72  
73  	/**
74  	 * 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.
75  	 */
76  	public UnprocessableEntityException(String theMessage) {
77  		super(STATUS_CODE, theMessage);
78  	}
79  
80  	/**
81  	 * 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.
82  	 */
83  	public UnprocessableEntityException(String theMessage, Throwable theCause) {
84  		super(STATUS_CODE, theMessage, theCause);
85  	}
86  
87  	/**
88  	 * 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.
89  	 */
90  	public UnprocessableEntityException(String... theMessage) {
91  		super(STATUS_CODE, theMessage);
92  	}
93  
94  }