diff --git a/spring-web/src/main/java/org/springframework/web/ErrorResponse.java b/spring-web/src/main/java/org/springframework/web/ErrorResponse.java index 86c2d6472106..3f239de6e264 100644 --- a/spring-web/src/main/java/org/springframework/web/ErrorResponse.java +++ b/spring-web/src/main/java/org/springframework/web/ErrorResponse.java @@ -100,14 +100,15 @@ default Object[] getDetailMessageArguments(MessageSource messageSource, Locale l *

By default this is initialized via * {@link #getDefaultDetailMessageCode(Class, String)}. */ - default String getTitleCode() { + default String getTitleMessageCode() { return getDefaultTitleMessageCode(getClass()); } /** * Resolve the {@link #getDetailMessageCode() detailMessageCode} and the - * {@link #getTitleCode() titleCode} through the given {@link MessageSource}, - * and if found, update the "detail" and "title!" fields respectively. + * {@link #getTitleMessageCode() titleCode} through the given + * {@link MessageSource}, and if found, update the "detail" and "title!" + * fields respectively. * @param messageSource the {@code MessageSource} to use for the lookup * @param locale the {@code Locale} to use for the lookup */ @@ -118,7 +119,7 @@ default ProblemDetail updateAndGetBody(@Nullable MessageSource messageSource, Lo if (detail != null) { getBody().setDetail(detail); } - String title = messageSource.getMessage(getTitleCode(), null, null, locale); + String title = messageSource.getMessage(getTitleMessageCode(), null, null, locale); if (title != null) { getBody().setTitle(title); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java index 61db9627eb8c..99f8e386fa3e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java @@ -306,12 +306,11 @@ protected Mono> handleErrorResponseException( * @return the created {@code ProblemDetail} instance */ protected ProblemDetail createProblemDetail( - Exception ex, HttpStatusCode status, @Nullable HttpHeaders headers, - String defaultDetail, @Nullable String detailMessageCode, @Nullable Object[] detailMessageArguments, - ServerWebExchange exchange) { + Exception ex, HttpStatusCode status, String defaultDetail, @Nullable String detailMessageCode, + @Nullable Object[] detailMessageArguments, ServerWebExchange exchange) { ErrorResponse response = ErrorResponse.createFor( - ex, status, headers, defaultDetail, detailMessageCode, detailMessageArguments); + ex, status, null, defaultDetail, detailMessageCode, detailMessageArguments); return response.updateAndGetBody(this.messageSource, getLocale(exchange)); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandlerTests.java index 74c7ecc300db..777bfd7f931f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandlerTests.java @@ -279,7 +279,7 @@ protected Mono> handleErrorResponseException( public Mono> handleException(IllegalStateException ex, ServerWebExchange exchange) { HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; - ProblemDetail body = createProblemDetail(ex, status, null, ex.getMessage(), null, new Object[] {"A"}, exchange); + ProblemDetail body = createProblemDetail(ex, status, ex.getMessage(), null, new Object[] {"A"}, exchange); return handleExceptionInternal(ex, body, null, status, exchange); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java index ca596bb0c6f8..a30433a34941 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java @@ -394,7 +394,7 @@ protected ResponseEntity handleConversionNotSupported( Object[] args = {ex.getPropertyName(), ex.getValue()}; String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "'"; - ProblemDetail body = createProblemDetail(ex, status, headers, defaultDetail, null, args, request); + ProblemDetail body = createProblemDetail(ex, status, defaultDetail, null, args, request); return handleExceptionInternal(ex, body, headers, status, request); } @@ -419,7 +419,7 @@ protected ResponseEntity handleTypeMismatch( Object[] args = {ex.getPropertyName(), ex.getValue()}; String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "'"; String messageCode = ErrorResponse.getDefaultDetailMessageCode(TypeMismatchException.class, null); - ProblemDetail body = createProblemDetail(ex, status, headers, defaultDetail, messageCode, args, request); + ProblemDetail body = createProblemDetail(ex, status, defaultDetail, messageCode, args, request); return handleExceptionInternal(ex, body, headers, status, request); } @@ -441,7 +441,7 @@ protected ResponseEntity handleTypeMismatch( protected ResponseEntity handleHttpMessageNotReadable( HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { - ProblemDetail body = createProblemDetail(ex, status, headers, "Failed to read request", null, null, request); + ProblemDetail body = createProblemDetail(ex, status, "Failed to read request", null, null, request); return handleExceptionInternal(ex, body, headers, status, request); } @@ -462,7 +462,7 @@ protected ResponseEntity handleHttpMessageNotReadable( protected ResponseEntity handleHttpMessageNotWritable( HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { - ProblemDetail body = createProblemDetail(ex, status, headers, "Failed to write request", null, null, request); + ProblemDetail body = createProblemDetail(ex, status, "Failed to write request", null, null, request); return handleExceptionInternal(ex, body, headers, status, request); } @@ -505,12 +505,11 @@ protected ResponseEntity handleBindException( * @since 6.0 */ protected ProblemDetail createProblemDetail( - Exception ex, HttpStatusCode status, @Nullable HttpHeaders headers, - String defaultDetail, @Nullable String detailMessageCode, @Nullable Object[] detailMessageArguments, - WebRequest request) { + Exception ex, HttpStatusCode status, String defaultDetail, @Nullable String detailMessageCode, + @Nullable Object[] detailMessageArguments, WebRequest request) { ErrorResponse errorResponse = ErrorResponse.createFor( - ex, status, headers, defaultDetail, detailMessageCode, detailMessageArguments); + ex, status, null, defaultDetail, detailMessageCode, detailMessageArguments); return errorResponse.updateAndGetBody(this.messageSource, LocaleContextHolder.getLocale()); }