I am using Spring Boot 1.3.X and have the following:
@RestController @RequestMapping(path = "/foo") public class FooController { @RequestMapping(method = RequestMethod.GET, params = { "fooBar" }) public Collection<Entry> firstFoo() {
It works as expected. When passing the wrong parameter, the following exception occurs:
{ "error": "Bad Request", "exception": "org.springframework.web.bind.UnsatisfiedServletRequestParameterException", "message": "Parameter conditions \"fooBar\" OR \"anotherFooBar\" not met for actual request parameters: elementalFormulae={C11}", "path": "/foo", "status": 400, "timestamp": 1455287433961 }
Then I created an ExceptionHandler as shown below:
@ControllerAdvice public class ExcptionController { @ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Invalid parameter") @ExceptionHandler(UnsatisfiedServletRequestParameterException.class) private void foo() {
Which raises the following exception:
{ "error": "Bad Request", "exception": "org.springframework.web.bind.UnsatisfiedServletRequestParameterException", "message": "Invalid parameter", "path": "/api/foo", "status": 400, "timestamp": 1455287904886 }
Is it possible to exclude an exception field from a JSON view?
source share