Better exception message for missing @RequestBody method parameter
2017-03-31 14:20
1201 查看
https://jira.spring.io/browse/SPR-12888
It would be nice if when that exception could have a reference to the parameter name that was missing, or if the message itself included it instead of the MethodParameter#toString(). I'll eventually want to internationalize the message I produce, so the parameter name is preferable.
Comments
Work Log
History
Activity
Transitions
Ascending order - Click to sort in descending order
Permalink
![](https://secure.gravatar.com/avatar/4b12b9c0c665bc0345467c1a218ed0f7?d=mm&s=16)
Rossen Stoyanchev added a comment - 06/Apr/15 2:57 PM
The HttpMessageNotReadableException can be raised from many places where a method parameter does not apply so adding a new field to the exception isn't ideal. I considered sub-classing the exception but what I've done instead is to print the full method signature to improve the error message. Also we now support injecting the selected HandlerMethod into an @ExceptionHandler method so you can obtain the full information on the @RequestMapping method we were trying to call.
Permalink
![](https://secure.gravatar.com/avatar/4b12b9c0c665bc0345467c1a218ed0f7?d=mm&s=16)
Rossen Stoyanchev added a comment - 06/Apr/15 2:57 PM
Resolving for now but feel free to comment further.
Description
When I use @RequestBody on one of my controllers for a required parameter, I need some useful way of saying which parameter was missing if it's not there. The exception message I see currently looks like this:Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter@a8b8886e |
at org.springframework.test.util.MatcherAssertionErrors.assertThat(MatcherAssertionErrors.java:80) |
at org.springframework.test.util.JsonPathExpectationsHelper.assertValue(JsonPathExpectationsHelper.java:92) |
at org.springframework.test.web.servlet.result.JsonPathResultMatchers$1.match(JsonPathResultMatchers.java:56) |
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:152) |
... |
Activity
AllComments
Work Log
History
Activity
Transitions
Ascending order - Click to sort in descending order
Permalink
Rossen Stoyanchev added a comment - 06/Apr/15 2:57 PM
The HttpMessageNotReadableException can be raised from many places where a method parameter does not apply so adding a new field to the exception isn't ideal. I considered sub-classing the exception but what I've done instead is to print the full method signature to improve the error message. Also we now support injecting the selected HandlerMethod into an @ExceptionHandler method so you can obtain the full information on the @RequestMapping method we were trying to call.
Permalink
Rossen Stoyanchev added a comment - 06/Apr/15 2:57 PM
Resolving for now but feel free to comment further.
相关文章推荐
- org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing
- message[java.lang.IllegalArgumentException: Missing method or missing parameter converters
- org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'xxxx' is not present
- Elasticsearch Exception:Message not fully read (response) for requestId
- javax.servlet.jsp.JspException: Missing message for key "xxxxxx"
- selenium.common.exceptions.WebDriverException: Message: Missing 'type' parameter
- "error":400,"reason":"Bad Request","message":"No values provided for the request parameter '_action
- MissingMethodException: Default constructor not found for type
- The method queryForMap(String, Object...) from the type JdbcTemplate refers to the missing type DataAccessException
- Missing URI template variable 'employeeNumber' for method parameter of type String
- javax.servlet.jsp.JspException: No getter method for property requestId of bean org.apache.struts.ta
- 偶现的MissingServletRequestParameterException,谁动了我的参数?
- No message body writer has been found for response class HibernateQueryException问题解决
- springCloud:"exception":"org.springframework.web.bind.MissingServletRequestParameterException","mess
- Spring Extension (2) — Annotation RequestAttribute for Controller method Parameter Injection
- 【Robotframework】WebDriverException: Message: Missing 'type' parameter
- Spring MVC org.springframework.web.bind.MissingServletRequestParameterException解决办法
- org.springframework.web.bind.MissingServletRequestParameterException: Required Long parameter 'label
- SQLException:Parameter metadata not available for the given statement
- CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1