Skip to content

Commit

Permalink
Merge pull request #540 from CarthageKing/feature-resource_not_suppor…
Browse files Browse the repository at this point in the history
…ted-fix

return 404 instead of 400 when the FHIR resource/endpoint is not recognized/not supported
  • Loading branch information
jamesagnew committed Jan 20, 2017
2 parents dc17157 + b59c24a commit 4e2e54a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
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.IServerInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
Expand Down Expand Up @@ -253,7 +254,7 @@ public BaseMethodBinding<?> determineResourceMethod(RequestDetails requestDetail
} else {
resourceBinding = myResourceNameToBinding.get(resourceName);
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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public void testHistoryResourceType() throws Exception {
}

@Test
public void testInvalidResourceTriggers400() throws Exception {
public void testInvalidResourceTriggers404() throws Exception {

HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/FooResource?blah=bar");
HttpResponse status = ourClient.execute(httpGet);
Expand All @@ -537,7 +537,7 @@ public void testInvalidResourceTriggers400() throws Exception {

ourLog.info("Response was:\n{}", responseContent);

assertEquals(400, status.getStatusLine().getStatusCode());
assertEquals(404, status.getStatusLine().getStatusCode());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testOptionsForNonBasePath1() throws Exception {
IOUtils.closeQuietly(status.getEntity().getContent());

ourLog.info(responseContent);
assertEquals(400, status.getStatusLine().getStatusCode());
assertEquals(404, status.getStatusLine().getStatusCode());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void testGetInvalidResourceNoAcceptHeader() throws Exception {
IOUtils.closeQuietly(status.getEntity().getContent());

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, (stringContainsInOrder("Unknown resource type 'Foobar'")));
Expand Down

0 comments on commit 4e2e54a

Please sign in to comment.