Reputation: 399
Our controller looks like this -
@RestController
@RequestMapping(value="api")
@Validated
public class SampleController {
@RequestMapping(value = {"/test"}, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void test(
@RequestParam(value = "testCode",required=true) String merchantCode
) throws Exception{
System.out.print("This is Test");
}
}
Here if we do not specify the required parameter "testCode" in our request we get "400 Bad Request", but the message section of the error response remains blank.
Response we are getting -
{"timestamp":1592441286607,"status":400,"error":"Bad Request","message":"","path":"/test"}
But expected is -
{"timestamp":1592441286607,"status":400,"error":"Bad Request","message":"Required String parameter 'testCode' is not present","path":"/test"}
We are using below Spring dependencies -
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
<spring-framework.version>5.2.6.RELEASE</spring-framework.version>
What I have seen is for this we are getting MissingServletRequestParameterException, but in the exception the message is coming as blank("").
Upvotes: 6
Views: 6210
Reputation: 602
Configuration in application.yml
server:
error:
include-message: always
include-binding-errors: always
include-stacktrace: on_trace_param
include-exception: true
Upvotes: 1
Reputation: 399
I just updated the bootstrap.yml with server.error.include-message=always
. It appears from Spring 2.3.0 the default behavior of Spring has changed. We can refer the following link from more details https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#changes-to-the-default-error-pages-content
Upvotes: 8