Exception enhancements

This commit is contained in:
jamesagnew 2014-08-20 09:01:09 -04:00
parent 71e6efbc31
commit f8a5acfed9
2 changed files with 49 additions and 19 deletions

View File

@ -1,7 +1,5 @@
package ca.uhn.fhir.rest.server.exceptions; package ca.uhn.fhir.rest.server.exceptions;
import java.text.ParseException;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
/* /*
@ -41,7 +39,7 @@ public class AuthenticationException extends BaseServerResponseException {
super(STATUS_CODE, theMessage); super(STATUS_CODE, theMessage);
} }
public AuthenticationException(String theMessage, ParseException theCause) { public AuthenticationException(String theMessage, Throwable theCause) {
super(STATUS_CODE, theMessage, theCause); super(STATUS_CODE, theMessage, theCause);
} }

View File

@ -27,9 +27,8 @@ import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
*/ */
/** /**
* Base class for RESTful client and server exceptions. RESTful client methods * Base class for RESTful client and server exceptions. RESTful client methods will only throw exceptions which are
* will only throw exceptions which are subclasses of this exception type, and * subclasses of this exception type, and RESTful server methods should also only call subclasses of this exception
* RESTful server methods should also only call subclasses of this exception
* type. * type.
*/ */
public abstract class BaseServerResponseException extends RuntimeException { public abstract class BaseServerResponseException extends RuntimeException {
@ -50,10 +49,8 @@ public abstract class BaseServerResponseException extends RuntimeException {
} }
private final OperationOutcome myOperationOutcome; private final OperationOutcome myOperationOutcome;
private String myResponseBody; private String myResponseBody;
private String myResponseMimeType; private String myResponseMimeType;
private int myStatusCode; private int myStatusCode;
/** /**
@ -77,6 +74,9 @@ public abstract class BaseServerResponseException extends RuntimeException {
* The HTTP status code corresponding to this problem * The HTTP status code corresponding to this problem
* @param theMessage * @param theMessage
* The message * The message
* @param theOperationOutcome
* An OperationOutcome resource to return to the calling client (in a server) or the OperationOutcome
* that was returned from the server (in a client)
*/ */
public BaseServerResponseException(int theStatusCode, String theMessage, OperationOutcome theOperationOutcome) { public BaseServerResponseException(int theStatusCode, String theMessage, OperationOutcome theOperationOutcome) {
super(theMessage); super(theMessage);
@ -100,6 +100,25 @@ public abstract class BaseServerResponseException extends RuntimeException {
myOperationOutcome = null; myOperationOutcome = null;
} }
/**
* Constructor
*
* @param theStatusCode
* The HTTP status code corresponding to this problem
* @param theMessage
* The message
* @param theCause
* The underlying cause exception
* @param theOperationOutcome
* An OperationOutcome resource to return to the calling client (in a server) or the OperationOutcome
* that was returned from the server (in a client)
*/
public BaseServerResponseException(int theStatusCode, String theMessage, Throwable theCause, OperationOutcome theOperationOutcome) {
super(theMessage, theCause);
myStatusCode = theStatusCode;
myOperationOutcome = theOperationOutcome;
}
/** /**
* Constructor * Constructor
* *
@ -115,17 +134,32 @@ public abstract class BaseServerResponseException extends RuntimeException {
} }
/** /**
* Returns the {@link OperationOutcome} resource if any which was supplied * Constructor
* in the response, or <code>null</code> *
* @param theStatusCode
* The HTTP status code corresponding to this problem
* @param theCause
* The underlying cause exception
* @param theOperationOutcome
* An OperationOutcome resource to return to the calling client (in a server) or the OperationOutcome
* that was returned from the server (in a client)
*/
public BaseServerResponseException(int theStatusCode, Throwable theCause, OperationOutcome theOperationOutcome) {
super(theCause.toString(), theCause);
myStatusCode = theStatusCode;
myOperationOutcome = theOperationOutcome;
}
/**
* Returns the {@link OperationOutcome} resource if any which was supplied in the response, or <code>null</code>
*/ */
public OperationOutcome getOperationOutcome() { public OperationOutcome getOperationOutcome() {
return myOperationOutcome; return myOperationOutcome;
} }
/** /**
* In a RESTful client, this method will be populated with the body of the * In a RESTful client, this method will be populated with the body of the HTTP respone if one was provided by the
* HTTP respone if one was provided by the server, or <code>null</code> * server, or <code>null</code> otherwise.
* otherwise.
* <p> * <p>
* In a restful server, this method is currently ignored. * In a restful server, this method is currently ignored.
* </p> * </p>
@ -135,8 +169,8 @@ public abstract class BaseServerResponseException extends RuntimeException {
} }
/** /**
* In a RESTful client, this method will be populated with the HTTP status * In a RESTful client, this method will be populated with the HTTP status code that was returned with the HTTP
* code that was returned with the HTTP response. * response.
* <p> * <p>
* In a restful server, this method is currently ignored. * In a restful server, this method is currently ignored.
* </p> * </p>
@ -153,16 +187,14 @@ public abstract class BaseServerResponseException extends RuntimeException {
} }
/** /**
* This method is currently only called internally by HAPI, it should not be * This method is currently only called internally by HAPI, it should not be called by user code.
* called by user code.
*/ */
public void setResponseBody(String theResponseBody) { public void setResponseBody(String theResponseBody) {
myResponseBody = theResponseBody; myResponseBody = theResponseBody;
} }
/** /**
* This method is currently only called internally by HAPI, it should not be * This method is currently only called internally by HAPI, it should not be called by user code.
* called by user code.
*/ */
public void setResponseMimeType(String theResponseMimeType) { public void setResponseMimeType(String theResponseMimeType) {
myResponseMimeType = theResponseMimeType; myResponseMimeType = theResponseMimeType;