Skip to content

Commit 921eead

Browse files
committed
Minor refactoring after recent commits
See gh-29384
1 parent e71057d commit 921eead

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

spring-web/src/main/java/org/springframework/web/ErrorResponse.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,15 @@ default Object[] getDetailMessageArguments(MessageSource messageSource, Locale l
100100
* <p>By default this is initialized via
101101
* {@link #getDefaultDetailMessageCode(Class, String)}.
102102
*/
103-
default String getTitleCode() {
103+
default String getTitleMessageCode() {
104104
return getDefaultTitleMessageCode(getClass());
105105
}
106106

107107
/**
108108
* Resolve the {@link #getDetailMessageCode() detailMessageCode} and the
109-
* {@link #getTitleCode() titleCode} through the given {@link MessageSource},
110-
* and if found, update the "detail" and "title!" fields respectively.
109+
* {@link #getTitleMessageCode() titleCode} through the given
110+
* {@link MessageSource}, and if found, update the "detail" and "title!"
111+
* fields respectively.
111112
* @param messageSource the {@code MessageSource} to use for the lookup
112113
* @param locale the {@code Locale} to use for the lookup
113114
*/
@@ -118,7 +119,7 @@ default ProblemDetail updateAndGetBody(@Nullable MessageSource messageSource, Lo
118119
if (detail != null) {
119120
getBody().setDetail(detail);
120121
}
121-
String title = messageSource.getMessage(getTitleCode(), null, null, locale);
122+
String title = messageSource.getMessage(getTitleMessageCode(), null, null, locale);
122123
if (title != null) {
123124
getBody().setTitle(title);
124125
}

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,11 @@ protected Mono<ResponseEntity<Object>> handleErrorResponseException(
306306
* @return the created {@code ProblemDetail} instance
307307
*/
308308
protected ProblemDetail createProblemDetail(
309-
Exception ex, HttpStatusCode status, @Nullable HttpHeaders headers,
310-
String defaultDetail, @Nullable String detailMessageCode, @Nullable Object[] detailMessageArguments,
311-
ServerWebExchange exchange) {
309+
Exception ex, HttpStatusCode status, String defaultDetail, @Nullable String detailMessageCode,
310+
@Nullable Object[] detailMessageArguments, ServerWebExchange exchange) {
312311

313312
ErrorResponse response = ErrorResponse.createFor(
314-
ex, status, headers, defaultDetail, detailMessageCode, detailMessageArguments);
313+
ex, status, null, defaultDetail, detailMessageCode, detailMessageArguments);
315314

316315
return response.updateAndGetBody(this.messageSource, getLocale(exchange));
317316
}

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandlerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ protected Mono<ResponseEntity<Object>> handleErrorResponseException(
279279

280280
public Mono<ResponseEntity<Object>> handleException(IllegalStateException ex, ServerWebExchange exchange) {
281281
HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
282-
ProblemDetail body = createProblemDetail(ex, status, null, ex.getMessage(), null, new Object[] {"A"}, exchange);
282+
ProblemDetail body = createProblemDetail(ex, status, ex.getMessage(), null, new Object[] {"A"}, exchange);
283283
return handleExceptionInternal(ex, body, null, status, exchange);
284284
}
285285
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ protected ResponseEntity<Object> handleConversionNotSupported(
394394

395395
Object[] args = {ex.getPropertyName(), ex.getValue()};
396396
String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "'";
397-
ProblemDetail body = createProblemDetail(ex, status, headers, defaultDetail, null, args, request);
397+
ProblemDetail body = createProblemDetail(ex, status, defaultDetail, null, args, request);
398398

399399
return handleExceptionInternal(ex, body, headers, status, request);
400400
}
@@ -419,7 +419,7 @@ protected ResponseEntity<Object> handleTypeMismatch(
419419
Object[] args = {ex.getPropertyName(), ex.getValue()};
420420
String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "'";
421421
String messageCode = ErrorResponse.getDefaultDetailMessageCode(TypeMismatchException.class, null);
422-
ProblemDetail body = createProblemDetail(ex, status, headers, defaultDetail, messageCode, args, request);
422+
ProblemDetail body = createProblemDetail(ex, status, defaultDetail, messageCode, args, request);
423423

424424
return handleExceptionInternal(ex, body, headers, status, request);
425425
}
@@ -441,7 +441,7 @@ protected ResponseEntity<Object> handleTypeMismatch(
441441
protected ResponseEntity<Object> handleHttpMessageNotReadable(
442442
HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
443443

444-
ProblemDetail body = createProblemDetail(ex, status, headers, "Failed to read request", null, null, request);
444+
ProblemDetail body = createProblemDetail(ex, status, "Failed to read request", null, null, request);
445445
return handleExceptionInternal(ex, body, headers, status, request);
446446
}
447447

@@ -462,7 +462,7 @@ protected ResponseEntity<Object> handleHttpMessageNotReadable(
462462
protected ResponseEntity<Object> handleHttpMessageNotWritable(
463463
HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
464464

465-
ProblemDetail body = createProblemDetail(ex, status, headers, "Failed to write request", null, null, request);
465+
ProblemDetail body = createProblemDetail(ex, status, "Failed to write request", null, null, request);
466466
return handleExceptionInternal(ex, body, headers, status, request);
467467
}
468468

@@ -505,12 +505,11 @@ protected ResponseEntity<Object> handleBindException(
505505
* @since 6.0
506506
*/
507507
protected ProblemDetail createProblemDetail(
508-
Exception ex, HttpStatusCode status, @Nullable HttpHeaders headers,
509-
String defaultDetail, @Nullable String detailMessageCode, @Nullable Object[] detailMessageArguments,
510-
WebRequest request) {
508+
Exception ex, HttpStatusCode status, String defaultDetail, @Nullable String detailMessageCode,
509+
@Nullable Object[] detailMessageArguments, WebRequest request) {
511510

512511
ErrorResponse errorResponse = ErrorResponse.createFor(
513-
ex, status, headers, defaultDetail, detailMessageCode, detailMessageArguments);
512+
ex, status, null, defaultDetail, detailMessageCode, detailMessageArguments);
514513

515514
return errorResponse.updateAndGetBody(this.messageSource, LocaleContextHolder.getLocale());
516515
}

0 commit comments

Comments
 (0)