diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index d9ebf418889..eb8cb3c9108 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -181,7 +181,7 @@ public abstract class RestfulServer extends HttpServlet { // resourceMethod.get } catch (AuthenticationException e) { - response.setStatus(401); + response.setStatus(e.getStatusCode()); response.getWriter().write(e.getMessage()); } catch (BaseServerResponseException e) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java index b24c538653c..bd49917fcf1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/exceptions/AuthenticationException.java @@ -5,8 +5,19 @@ import javax.servlet.ServletException; /** * Created by dsotnikov on 3/10/2014. */ -public class AuthenticationException extends ServletException { +public class AuthenticationException extends BaseServerResponseException { private static final long serialVersionUID = 1L; + public AuthenticationException() { + super(401, "Client unauthorized"); + } + + public AuthenticationException(String theMessage) { + super(401, theMessage); + } + + public AuthenticationException(int theStatusCode, String theMessage) { + super(theStatusCode, theMessage); + } } \ No newline at end of file