Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exception message for missing @RequestBody method parameter [SPR-12888] #17486

Closed
spring-issuemaster opened this issue Apr 3, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Apr 3, 2015

Martin Meyer opened SPR-12888 and commented

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)
...

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.


Affects: 4.1.3

Referenced from: commits 13403d5

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 6, 2015

Rossen Stoyanchev commented

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.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 6, 2015

Rossen Stoyanchev commented

Resolving for now but feel free to comment further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.