Skip to content

Commit 5c08e23

Browse files
committed
Merge pull request spring-projects#15799 from Johnny Lim
* spring-projectsgh-15799: Polish Closes spring-projectsgh-15799
2 parents b5c9afc + 9f6c5e4 commit 5c08e23

File tree

4 files changed

+25
-33
lines changed

4 files changed

+25
-33
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTags.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -131,43 +131,36 @@ public static Tag clientName(HttpRequest request) {
131131
}
132132

133133
/**
134-
* Creates a {@code outcome} {@code Tag} derived from the
134+
* Creates an {@code outcome} {@code Tag} derived from the
135135
* {@link ClientHttpResponse#getStatusCode() status} of the given {@code response}.
136136
* @param response the response
137137
* @return the outcome tag
138138
* @since 2.2.0
139139
*/
140140
public static Tag outcome(ClientHttpResponse response) {
141-
HttpStatus status = extractStatus(response);
142-
if (status != null) {
143-
if (status.is1xxInformational()) {
144-
return OUTCOME_INFORMATIONAL;
145-
}
146-
if (status.is2xxSuccessful()) {
147-
return OUTCOME_SUCCESS;
148-
}
149-
if (status.is3xxRedirection()) {
150-
return OUTCOME_REDIRECTION;
151-
}
152-
if (status.is4xxClientError()) {
153-
return OUTCOME_CLIENT_ERROR;
154-
}
155-
if (status.is5xxServerError()) {
156-
return OUTCOME_SERVER_ERROR;
157-
}
158-
}
159-
return OUTCOME_UNKNOWN;
160-
}
161-
162-
private static HttpStatus extractStatus(ClientHttpResponse response) {
163141
try {
164142
if (response != null) {
165-
return response.getStatusCode();
143+
HttpStatus statusCode = response.getStatusCode();
144+
if (statusCode.is1xxInformational()) {
145+
return OUTCOME_INFORMATIONAL;
146+
}
147+
if (statusCode.is2xxSuccessful()) {
148+
return OUTCOME_SUCCESS;
149+
}
150+
if (statusCode.is3xxRedirection()) {
151+
return OUTCOME_REDIRECTION;
152+
}
153+
if (statusCode.is4xxClientError()) {
154+
return OUTCOME_CLIENT_ERROR;
155+
}
156+
if (statusCode.is5xxServerError()) {
157+
return OUTCOME_SERVER_ERROR;
158+
}
166159
}
167-
return null;
160+
return OUTCOME_UNKNOWN;
168161
}
169-
catch (IOException | IllegalArgumentException exc) {
170-
return null;
162+
catch (IOException | IllegalArgumentException ex) {
163+
return OUTCOME_UNKNOWN;
171164
}
172165
}
173166

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static Tag clientName(ClientRequest request) {
126126
}
127127

128128
/**
129-
* Creates a {@code outcome} {@code Tag} derived from the
129+
* Creates an {@code outcome} {@code Tag} derived from the
130130
* {@link ClientResponse#statusCode() status} of the given {@code response}.
131131
* @param response the response
132132
* @return the outcome tag

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/client/RestTemplateExchangeTagsTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@
3434
*
3535
* @author Nishant Raut
3636
* @author Brian Clozel
37-
* @author Brian Clozel
3837
*/
3938
public class RestTemplateExchangeTagsTests {
4039

4140
@Test
42-
public void outcomeTagIsUnknownWhenResponseStatusIsNull() {
41+
public void outcomeTagIsUnknownWhenResponseIsNull() {
4342
Tag tag = RestTemplateExchangeTags.outcome(null);
4443
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
4544
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/web/reactive/client/WebClientExchangeTagsTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import static org.mockito.Mockito.mock;
3535

3636
/**
37-
* Tests for {@link WebClientExchangeTags}
37+
* Tests for {@link WebClientExchangeTags}.
3838
*
3939
* @author Brian Clozel
4040
* @author Nishant Raut
@@ -115,7 +115,7 @@ public void statusWhenClientException() {
115115
}
116116

117117
@Test
118-
public void outcomeTagIsUnknownWhenResponseStatusIsNull() {
118+
public void outcomeTagIsUnknownWhenResponseIsNull() {
119119
Tag tag = WebClientExchangeTags.outcome(null);
120120
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
121121
}
@@ -156,7 +156,7 @@ public void outcomeTagIsServerErrorWhenResponseIs5xx() {
156156
}
157157

158158
@Test
159-
public void outcomeTagIsUknownWhenResponseStatusIsUknown() {
159+
public void outcomeTagIsUnknownWhenResponseStatusIsUnknown() {
160160
given(this.response.statusCode()).willThrow(IllegalArgumentException.class);
161161
Tag tag = WebClientExchangeTags.outcome(this.response);
162162
assertThat(tag.getValue()).isEqualTo("UNKNOWN");

0 commit comments

Comments
 (0)