
Class BaseServerResponseException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AuthenticationException
,FhirClientConnectionException
,FhirClientInappropriateForServerException
,ForbiddenOperationException
,InternalErrorException
,InvalidRequestException
,InvalidResponseException
,MethodNotAllowedException
,NonFhirResponseException
,NotImplementedOperationException
,NotModifiedException
,PayloadTooLargeException
,ResourceGoneException
,ResourceNotFoundException
,ResourceVersionConflictException
,ResourceVersionNotSpecifiedException
,UnclassifiedServerFailureException
,UnprocessableEntityException
public abstract class BaseServerResponseException extends RuntimeException
Base class for RESTful client and server exceptions. RESTful client methods will only throw exceptions which are subclasses of this exception type, and RESTful server methods should also only call subclasses of this exception type.HAPI provides a number of subclasses of BaseServerResponseException, and each one corresponds to a specific HTTP status code. For example, if a IResourceProvider method throws
ResourceNotFoundException
, this is a signal to the server that anHTTP 404
should be returned to the client.See: A complete list of available exceptions is in the package summary. If an exception doesn't exist for a condition you want to represent, let us know by filing an issue in our tracker. You may also use
UnclassifiedServerFailureException
to represent any error code you want.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BaseServerResponseException(int theStatusCode, String theMessage)
ConstructorBaseServerResponseException(int theStatusCode, String... theMessages)
ConstructorBaseServerResponseException(int theStatusCode, String theMessage, Throwable theCause)
ConstructorBaseServerResponseException(int theStatusCode, String theMessage, Throwable theCause, IBaseOperationOutcome theBaseOperationOutcome)
ConstructorBaseServerResponseException(int theStatusCode, String theMessage, IBaseOperationOutcome theBaseOperationOutcome)
ConstructorBaseServerResponseException(int theStatusCode, Throwable theCause)
ConstructorBaseServerResponseException(int theStatusCode, Throwable theCause, IBaseOperationOutcome theBaseOperationOutcome)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BaseServerResponseException
addResponseHeader(String theName, String theValue)
Add a header which will be added to any responsesList<String>
getAdditionalMessages()
IBaseOperationOutcome
getOperationOutcome()
Returns theIBaseOperationOutcome
resource if any which was supplied in the response, ornull
String
getResponseBody()
In a RESTful client, this method will be populated with the body of the HTTP respone if one was provided by the server, ornull
otherwise.Map<String,List<String>>
getResponseHeaders()
Returns a map containing any headers which should be added to the outgoing response.String
getResponseMimeType()
In a RESTful client, this method will be populated with the HTTP status code that was returned with the HTTP response.int
getStatusCode()
Returns the HTTP status code corresponding to this problemboolean
hasResponseHeaders()
Does the exception have any headers which should be added to the outgoing response?boolean
isErrorMessageTrusted()
This flag can be used to signal to server infrastructure that the message supplied to this exception (ie to the constructor) is considered trusted and is safe to return to the calling client.static BaseServerResponseException
newInstance(int theStatusCode, String theMessage)
BaseServerResponseException
setErrorMessageTrusted(boolean theErrorMessageTrusted)
This flag can be used to signal to server infrastructure that the message supplied to this exception (ie to the constructor) is considered trusted and is safe to return to the calling client.void
setOperationOutcome(IBaseOperationOutcome theBaseOperationOutcome)
Sets the BaseOperationOutcome resource associated with this exception.void
setResponseBody(String theResponseBody)
This method is currently only called internally by HAPI, it should not be called by user code.void
setResponseMimeType(String theResponseMimeType)
This method is currently only called internally by HAPI, it should not be called by user code.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
BaseServerResponseException
public BaseServerResponseException(int theStatusCode, String theMessage)
Constructor- Parameters:
theStatusCode
- The HTTP status code corresponding to this problemtheMessage
- The message
-
BaseServerResponseException
public BaseServerResponseException(int theStatusCode, String... theMessages)
Constructor- Parameters:
theStatusCode
- The HTTP status code corresponding to this problemtheMessages
- The messages
-
BaseServerResponseException
public BaseServerResponseException(int theStatusCode, String theMessage, IBaseOperationOutcome theBaseOperationOutcome)
Constructor- Parameters:
theStatusCode
- The HTTP status code corresponding to this problemtheMessage
- The messagetheBaseOperationOutcome
- An BaseOperationOutcome resource to return to the calling client (in a server) or the BaseOperationOutcome that was returned from the server (in a client)
-
BaseServerResponseException
public BaseServerResponseException(int theStatusCode, String theMessage, Throwable theCause)
Constructor- Parameters:
theStatusCode
- The HTTP status code corresponding to this problemtheMessage
- The messagetheCause
- The cause
-
BaseServerResponseException
public BaseServerResponseException(int theStatusCode, String theMessage, Throwable theCause, IBaseOperationOutcome theBaseOperationOutcome)
Constructor- Parameters:
theStatusCode
- The HTTP status code corresponding to this problemtheMessage
- The messagetheCause
- The underlying cause exceptiontheBaseOperationOutcome
- An BaseOperationOutcome resource to return to the calling client (in a server) or the BaseOperationOutcome that was returned from the server (in a client)
-
BaseServerResponseException
public BaseServerResponseException(int theStatusCode, Throwable theCause)
Constructor- Parameters:
theStatusCode
- The HTTP status code corresponding to this problemtheCause
- The underlying cause exception
-
BaseServerResponseException
public BaseServerResponseException(int theStatusCode, Throwable theCause, IBaseOperationOutcome theBaseOperationOutcome)
Constructor- Parameters:
theStatusCode
- The HTTP status code corresponding to this problemtheCause
- The underlying cause exceptiontheBaseOperationOutcome
- An BaseOperationOutcome resource to return to the calling client (in a server) or the BaseOperationOutcome that was returned from the server (in a client)
-
-
Method Detail
-
isErrorMessageTrusted
public boolean isErrorMessageTrusted()
This flag can be used to signal to server infrastructure that the message supplied to this exception (ie to the constructor) is considered trusted and is safe to return to the calling client.
-
setErrorMessageTrusted
public BaseServerResponseException setErrorMessageTrusted(boolean theErrorMessageTrusted)
This flag can be used to signal to server infrastructure that the message supplied to this exception (ie to the constructor) is considered trusted and is safe to return to the calling client.
-
addResponseHeader
public BaseServerResponseException addResponseHeader(String theName, String theValue)
Add a header which will be added to any responses- Parameters:
theName
- The header nametheValue
- The header value- Returns:
- Returns a reference to
this
for easy method chaining - Since:
- 2.0
-
getAdditionalMessages
public List<String> getAdditionalMessages()
-
getOperationOutcome
public IBaseOperationOutcome getOperationOutcome()
Returns theIBaseOperationOutcome
resource if any which was supplied in the response, ornull
-
setOperationOutcome
public void setOperationOutcome(IBaseOperationOutcome theBaseOperationOutcome)
Sets the BaseOperationOutcome resource associated with this exception. In server implementations, this is the OperartionOutcome resource to include with the HTTP response. In client implementations you should not call this method.- Parameters:
theBaseOperationOutcome
- The BaseOperationOutcome resource Sets the BaseOperationOutcome resource associated with this exception. In server implementations, this is the OperartionOutcome resource to include with the HTTP response. In client implementations you should not call this method.
-
getResponseBody
public String getResponseBody()
In a RESTful client, this method will be populated with the body of the HTTP respone if one was provided by the server, ornull
otherwise.In a restful server, this method is currently ignored.
-
setResponseBody
public void setResponseBody(String theResponseBody)
This method is currently only called internally by HAPI, it should not be called by user code.
-
getResponseHeaders
public Map<String,List<String>> getResponseHeaders()
Returns a map containing any headers which should be added to the outgoing response. This methos creates the map if none exists, so it will never returnnull
- Since:
- 2.0 (note that this method existed in previous versions of HAPI but the method
signature has been changed from
Map<String, String[]>
toMap<String, List<String>>
-
getResponseMimeType
public String getResponseMimeType()
In a RESTful client, this method will be populated with the HTTP status code that was returned with the HTTP response.In a restful server, this method is currently ignored.
-
setResponseMimeType
public void setResponseMimeType(String theResponseMimeType)
This method is currently only called internally by HAPI, it should not be called by user code.
-
getStatusCode
public int getStatusCode()
Returns the HTTP status code corresponding to this problem
-
hasResponseHeaders
public boolean hasResponseHeaders()
Does the exception have any headers which should be added to the outgoing response?- Since:
- 2.0
- See Also:
getResponseHeaders()
-
newInstance
public static BaseServerResponseException newInstance(int theStatusCode, String theMessage)
-
-