001package ca.uhn.fhir.rest.server.exceptions;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
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 ca.uhn.fhir.context.FhirContext;
024import ca.uhn.fhir.rest.api.Constants;
025import ca.uhn.fhir.util.CoverageIgnore;
026import ca.uhn.fhir.util.OperationOutcomeUtil;
027import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
028
029/**
030 * 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".
031 *
032 * <p>
033 * This exception will generally contain an {@link IBaseOperationOutcome} instance which details the failure.
034 * </p>
035 *
036 * @see InvalidRequestException Which corresponds to an <b>HTTP 400 Bad Request</b> failure
037 */
038@CoverageIgnore
039public class UnprocessableEntityException extends BaseServerResponseException {
040
041        public static final int STATUS_CODE = Constants.STATUS_HTTP_422_UNPROCESSABLE_ENTITY;
042        private static final String DEFAULT_MESSAGE = "Unprocessable Entity";
043        private static final long serialVersionUID = 1L;
044
045        /**
046         * Constructor
047         *
048         * @param theMessage          The message to add to the status line
049         * @param theOperationOutcome The {@link IBaseOperationOutcome} resource to return to the client
050         */
051        public UnprocessableEntityException(String theMessage, IBaseOperationOutcome theOperationOutcome) {
052                super(STATUS_CODE, theMessage, theOperationOutcome);
053        }
054
055
056        /**
057         * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response
058         *
059         * @deprecated Use constructor with FhirContext argument
060         */
061        @Deprecated
062        public UnprocessableEntityException(IBaseOperationOutcome theOperationOutcome) {
063                super(STATUS_CODE, DEFAULT_MESSAGE, theOperationOutcome);
064        }
065
066        /**
067         * Constructor which accepts an {@link IBaseOperationOutcome} resource which will be supplied in the response
068         */
069        public UnprocessableEntityException(FhirContext theCtx, IBaseOperationOutcome theOperationOutcome) {
070                super(STATUS_CODE, OperationOutcomeUtil.getFirstIssueDetails(theCtx, theOperationOutcome), theOperationOutcome);
071        }
072
073        /**
074         * 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.
075         */
076        public UnprocessableEntityException(String theMessage) {
077                super(STATUS_CODE, theMessage);
078        }
079
080        /**
081         * 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.
082         */
083        public UnprocessableEntityException(String theMessage, Throwable theCause) {
084                super(STATUS_CODE, theMessage, theCause);
085        }
086
087        /**
088         * 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.
089         */
090        public UnprocessableEntityException(String... theMessage) {
091                super(STATUS_CODE, theMessage);
092        }
093
094}