return 404 instead of 400 when the FHIR resource/endpoint is not

recognized/not supported
This commit is contained in:
michael.i.calderero 2017-01-17 20:37:43 -06:00
parent 22f796fa7c
commit b59c24ab7c
4 changed files with 6 additions and 5 deletions

View File

@ -75,6 +75,7 @@ import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.NotModifiedException; import ca.uhn.fhir.rest.server.exceptions.NotModifiedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor; import ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
@ -253,7 +254,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
} else { } else {
resourceBinding = myResourceNameToBinding.get(resourceName); resourceBinding = myResourceNameToBinding.get(resourceName);
if (resourceBinding == null) { if (resourceBinding == null) {
throw new InvalidRequestException("Unknown resource type '" + resourceName + "' - Server knows how to handle: " + myResourceNameToBinding.keySet()); throw new ResourceNotFoundException("Unknown resource type '" + resourceName + "' - Server knows how to handle: " + myResourceNameToBinding.keySet());
} }
} }

View File

@ -527,7 +527,7 @@ public class RestfulServerMethodTest {
} }
@Test @Test
public void testInvalidResourceTriggers400() throws Exception { public void testInvalidResourceTriggers404() throws Exception {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/FooResource?blah=bar"); HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/FooResource?blah=bar");
HttpResponse status = ourClient.execute(httpGet); HttpResponse status = ourClient.execute(httpGet);
@ -537,7 +537,7 @@ public class RestfulServerMethodTest {
ourLog.info("Response was:\n{}", responseContent); ourLog.info("Response was:\n{}", responseContent);
assertEquals(400, status.getStatusLine().getStatusCode()); assertEquals(404, status.getStatusLine().getStatusCode());
} }
@Test @Test

View File

@ -82,7 +82,7 @@ public class ServerFeaturesDstu2Test {
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info(responseContent); ourLog.info(responseContent);
assertEquals(400, status.getStatusLine().getStatusCode()); assertEquals(404, status.getStatusLine().getStatusCode());
} }
/** /**

View File

@ -171,7 +171,7 @@ public class ResponseHighlightingInterceptorTest {
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Resp: {}", responseContent); ourLog.info("Resp: {}", responseContent);
assertEquals(400, status.getStatusLine().getStatusCode()); assertEquals(404, status.getStatusLine().getStatusCode());
assertThat(responseContent, not(stringContainsInOrder("<span class='hlTagName'>OperationOutcome</span>", "Unknown resource type 'Foobar' - Server knows how to handle"))); assertThat(responseContent, not(stringContainsInOrder("<span class='hlTagName'>OperationOutcome</span>", "Unknown resource type 'Foobar' - Server knows how to handle")));
assertThat(responseContent, (stringContainsInOrder("Unknown resource type 'Foobar'"))); assertThat(responseContent, (stringContainsInOrder("Unknown resource type 'Foobar'")));