Skip to content

Commit 2112e02

Browse files
committed
Polish
Closes gh-15952
1 parent 2c20d01 commit 2112e02

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ protected Mono<ServerResponse> renderDefaultErrorView(
215215
Date timestamp = (Date) error.get("timestamp");
216216
Object message = error.get("message");
217217
Object trace = error.get("trace");
218-
Object logPrefix = error.get("logPrefix");
218+
Object requestId = error.get("requestId");
219219
builder.append("<html><body><h1>Whitelabel Error Page</h1>").append(
220220
"<p>This application has no configured error view, so you are seeing this as a fallback.</p>")
221221
.append("<div id='created'>").append(timestamp).append("</div>")
222-
.append(logPrefix).append("<div>There was an unexpected error (type=")
222+
.append("<div>[").append(requestId)
223+
.append("] There was an unexpected error (type=")
223224
.append(htmlEscape(error.get("error"))).append(", status=")
224225
.append(htmlEscape(error.get("status"))).append(").</div>");
225226
if (message != null) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void jsonError() {
8383
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
8484
.jsonPath("path").isEqualTo(("/")).jsonPath("message")
8585
.isEqualTo("Expected!").jsonPath("exception").doesNotExist()
86-
.jsonPath("trace").doesNotExist().jsonPath("logPrefix")
86+
.jsonPath("trace").doesNotExist().jsonPath("requestId")
8787
.isEqualTo(this.logIdFilter.getLogId());
8888
this.outputCapture.expect(Matchers.allOf(
8989
containsString("500 Server Error for HTTP GET \"/\""),
@@ -99,7 +99,7 @@ public void notFound() {
9999
.expectBody().jsonPath("status").isEqualTo("404").jsonPath("error")
100100
.isEqualTo(HttpStatus.NOT_FOUND.getReasonPhrase()).jsonPath("path")
101101
.isEqualTo(("/notFound")).jsonPath("exception").doesNotExist()
102-
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId());
102+
.jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
103103
});
104104
}
105105

@@ -128,7 +128,7 @@ public void bindingResultError() {
128128
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path")
129129
.isEqualTo(("/bind")).jsonPath("exception").doesNotExist()
130130
.jsonPath("errors").isArray().jsonPath("message").isNotEmpty()
131-
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId());
131+
.jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
132132
});
133133
}
134134

@@ -145,7 +145,7 @@ public void includeStackTraceOnParam() {
145145
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
146146
.jsonPath("exception")
147147
.isEqualTo(IllegalStateException.class.getName())
148-
.jsonPath("trace").exists().jsonPath("logPrefix")
148+
.jsonPath("trace").exists().jsonPath("requestId")
149149
.isEqualTo(this.logIdFilter.getLogId());
150150
});
151151
}
@@ -161,7 +161,7 @@ public void alwaysIncludeStackTrace() {
161161
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
162162
.jsonPath("exception")
163163
.isEqualTo(IllegalStateException.class.getName())
164-
.jsonPath("trace").exists().jsonPath("logPrefix")
164+
.jsonPath("trace").exists().jsonPath("requestId")
165165
.isEqualTo(this.logIdFilter.getLogId());
166166
});
167167
}
@@ -177,7 +177,7 @@ public void neverIncludeStackTrace() {
177177
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
178178
.jsonPath("exception")
179179
.isEqualTo(IllegalStateException.class.getName())
180-
.jsonPath("trace").doesNotExist().jsonPath("logPrefix")
180+
.jsonPath("trace").doesNotExist().jsonPath("requestId")
181181
.isEqualTo(this.logIdFilter.getLogId());
182182
});
183183
}
@@ -193,7 +193,7 @@ public void statusException() {
193193
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase())
194194
.jsonPath("exception")
195195
.isEqualTo(ResponseStatusException.class.getName())
196-
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId());
196+
.jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
197197
});
198198
}
199199

@@ -326,7 +326,7 @@ private static final class LogIdFilter implements WebFilter {
326326

327327
@Override
328328
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
329-
this.logId = exchange.getLogPrefix();
329+
this.logId = exchange.getRequest().getId();
330330
return chain.filter(exchange);
331331
}
332332

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* <li>errors - Any {@link ObjectError}s from a {@link BindingResult} exception
4545
* <li>trace - The exception stack trace</li>
4646
* <li>path - The URL path when the exception was raised</li>
47+
* <li>requestId - Unique Id associated with the current request</li>
4748
* </ul>
4849
*
4950
* @author Brian Clozel
@@ -86,7 +87,7 @@ public Map<String, Object> getErrorAttributes(ServerRequest request,
8687
errorAttributes.put("status", errorStatus.value());
8788
errorAttributes.put("error", errorStatus.getReasonPhrase());
8889
errorAttributes.put("message", determineMessage(error));
89-
errorAttributes.put("logPrefix", request.exchange().getLogPrefix());
90+
errorAttributes.put("requestId", request.exchange().getRequest().getId());
9091
handleException(errorAttributes, determineException(error), includeStackTrace);
9192
return errorAttributes;
9293
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ public void includeLogPrefix() {
212212
ServerRequest serverRequest = buildServerRequest(request, NOT_FOUND);
213213
Map<String, Object> attributes = this.errorAttributes
214214
.getErrorAttributes(serverRequest, false);
215-
assertThat(attributes.get("logPrefix"))
216-
.isEqualTo(serverRequest.exchange().getLogPrefix());
215+
assertThat(attributes.get("requestId"))
216+
.isEqualTo(serverRequest.exchange().getRequest().getId());
217217
}
218218

219219
@Test

0 commit comments

Comments
 (0)