There is a discrepancy between the documentation and the actual implementation regarding the message codes for ErrorResponses.
https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-ann-rest-exceptions.html#mvc-ann-rest-exceptions-i18n describes the following pattern:
The default strategy for message codes follows the pattern: problemDetail.[type|title|detail].[fully qualified exception class name]
As you can see in the following references, detail
is not used when searching for the message code. This does happen for problemDetail.title
and problemDetail.type
https://github.com/spring-projects/spring-framework/blob/0435e9c49e299a4db345cc120f29e844ccca96f1/spring-web/src/main/java/org/springframework/web/ErrorResponse.java#L162
https://github.com/spring-projects/spring-framework/blob/0435e9c49e299a4db345cc120f29e844ccca96f1/spring-web/src/main/java/org/springframework/web/ErrorResponse.java#L172
https://github.com/spring-projects/spring-framework/blob/0435e9c49e299a4db345cc120f29e844ccca96f1/spring-web/src/main/java/org/springframework/web/ErrorResponse.java#L184
Expected message code according to documentation: - problemDetail.detail.org.springframework.web.bind.MethodArgumentNotValidException
Actual message code that gets resolved - problemDetail.org.springframework.web.bind.MethodArgumentNotValidException
Comment From: snicoll
Closing in favor of PR #32446