Skip to content

Improve handling of non-standard status codes in WebMvcTags #17998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,21 @@ public static Tag exception(Throwable exception) {
*/
public static Tag outcome(HttpServletResponse response) {
if (response != null) {
HttpStatus status = extractStatus(response);
if (status != null) {
if (status.is1xxInformational()) {
HttpStatus.Series series = HttpStatus.Series.resolve(response.getStatus());
if (series != null) {
switch (series) {
case INFORMATIONAL:
return OUTCOME_INFORMATIONAL;
}
if (status.is2xxSuccessful()) {
case SUCCESSFUL:
return OUTCOME_SUCCESS;
}
if (status.is3xxRedirection()) {
case REDIRECTION:
return OUTCOME_REDIRECTION;
}
if (status.is4xxClientError()) {
case CLIENT_ERROR:
return OUTCOME_CLIENT_ERROR;
case SERVER_ERROR:
return OUTCOME_SERVER_ERROR;
}
}
return OUTCOME_SERVER_ERROR;
}
return OUTCOME_UNKNOWN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,25 @@ void outcomeTagIsClientErrorWhenResponseIs4xx() {
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}

@Test
void outcomeTagIsClientErrorWhenResponseIsNonStandardInClientSeries() {
this.response.setStatus(490);
Tag tag = WebMvcTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}

@Test
void outcomeTagIsServerErrorWhenResponseIs5xx() {
this.response.setStatus(500);
Tag tag = WebMvcTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("SERVER_ERROR");
}

@Test
void outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries() {
this.response.setStatus(701);
Tag tag = WebMvcTags.outcome(this.response);
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
}

}