Skip to content

Commit 5f14703

Browse files
committed
Merge branch '6.1.x'
2 parents e02f8ca + 67d78eb commit 5f14703

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

spring-web/src/main/java/org/springframework/http/server/observation/DefaultServerRequestObservationConvention.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,14 @@ protected KeyValue exception(ServerRequestObservationContext context) {
160160
}
161161

162162
protected KeyValue outcome(ServerRequestObservationContext context) {
163-
if (context.getResponse() != null) {
164-
HttpStatusCode statusCode = HttpStatusCode.valueOf(context.getResponse().getStatus());
165-
return HttpOutcome.forStatus(statusCode);
163+
try {
164+
if (context.getResponse() != null) {
165+
HttpStatusCode statusCode = HttpStatusCode.valueOf(context.getResponse().getStatus());
166+
return HttpOutcome.forStatus(statusCode);
167+
}
168+
}
169+
catch (IllegalArgumentException ex) {
170+
return HTTP_OUTCOME_UNKNOWN;
166171
}
167172
return HTTP_OUTCOME_UNKNOWN;
168173
}

spring-web/src/test/java/org/springframework/http/server/observation/DefaultServerRequestObservationConventionTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -137,4 +137,16 @@ void addsKeyValuesForUnknownHttpMethodExchange() {
137137
.contains(KeyValue.of("http.url", "/test"));
138138
}
139139

140+
@Test
141+
void addsKeyValuesForInvalidStatusExchange() {
142+
this.request.setRequestURI("/test/invalidStatus");
143+
this.response.setStatus(0);
144+
145+
assertThat(this.convention.getLowCardinalityKeyValues(this.context)).hasSize(5)
146+
.contains(KeyValue.of("method", "GET"), KeyValue.of("uri", "UNKNOWN"), KeyValue.of("status", "0"),
147+
KeyValue.of("exception", "none"), KeyValue.of("outcome", "UNKNOWN"));
148+
assertThat(this.convention.getHighCardinalityKeyValues(this.context)).hasSize(1)
149+
.contains(KeyValue.of("http.url", "/test/invalidStatus"));
150+
}
151+
140152
}

0 commit comments

Comments
 (0)