ResponseStatusException reason as message code for ProblemDetail

See gh-30300
This commit is contained in:
Yanming Zhou
2023-04-06 17:18:27 +08:00
committed by rstoyanchev
parent 6697f01d05
commit a3532bfccc
2 changed files with 35 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ import org.springframework.lang.Nullable;
* {@code @RestController} or {@code RestControllerAdvice} class.
*
* @author Rossen Stoyanchev
* @author Yanming Zhou
* @since 6.0
* @see ErrorResponseException
*/
@@ -142,6 +143,14 @@ public interface ErrorResponse {
if (detail != null) {
getBody().setDetail(detail);
}
else {
// detail from ResponseStatusException reason may be message code
detail = getBody().getDetail();
if (detail != null) {
detail = messageSource.getMessage(detail, null, detail, locale);
getBody().setDetail(detail);
}
}
String title = messageSource.getMessage(getTitleMessageCode(), null, null, locale);
if (title != null) {
getBody().setTitle(title);