Skip to content

Commit

Permalink
WebApplicationExceptionMapper treats redirection as informational (#2316
Browse files Browse the repository at this point in the history
)

WebApplicationExceptionMapper treats redirection as informational
  • Loading branch information
schlosna authored Mar 29, 2022
1 parent f3ce90e commit b4d4628
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2316.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: WebApplicationExceptionMapper treats redirection as informational
links:
- https://github.com/palantir/conjure-java-runtime/pull/2316
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ final class WebApplicationExceptionMapper extends ListenableExceptionMapper<WebA
public Response toResponseInner(WebApplicationException exception) {
String errorInstanceId = UUID.randomUUID().toString();

if (exception.getResponse().getStatus() / 100 == 4 /* client error */) {
log.info("Error handling request", SafeArg.of("errorInstanceId", errorInstanceId), exception);
} else {
if (exception.getResponse().getStatusInfo().getFamily() == Response.Status.Family.SERVER_ERROR) {
log.error("Error handling request", SafeArg.of("errorInstanceId", errorInstanceId), exception);
} else {
log.info("Error handling request", SafeArg.of("errorInstanceId", errorInstanceId), exception);
}

if (exception instanceof NotAuthorizedException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.RedirectionException;
import javax.ws.rs.ServiceUnavailableException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -103,4 +104,17 @@ public void testNotExplicitlyHandledExceptions() throws Exception {
assertThat(response.getStatus()).isEqualTo(503);
assertThat(entity).doesNotContain("secret");
}

@Test
public void handle304NotModified() throws Exception {
Response response = mapper.toResponse(
new RedirectionException(Response.notModified("test-etag").build()));
String entity = objectMapper.writeValueAsString(response.getEntity());
assertThat(entity).contains("\"errorCode\" : \"javax.ws.rs.RedirectionException\"");
assertThat(entity).contains("\"errorName\" : \"RedirectionException\"");
assertThat(entity).contains("\"errorInstanceId\" : ");
assertThat(response.getStatus()).isEqualTo(304);
assertThat(response.getHeaderString("ETag")).isNull();
assertThat(entity).doesNotContain("secret");
}
}

0 comments on commit b4d4628

Please sign in to comment.