Używam Wiosna Boot 1.3.x i mają następujące:Wiosna Boot @ExceptionHandler ukryj Wyjątek Nazwa
@RestController
@RequestMapping(path = "/foo")
public class FooController {
@RequestMapping(method = RequestMethod.GET, params = { "fooBar" })
public Collection<Entry> firstFoo() {
//Do something
}
@RequestMapping(method = RequestMethod.GET, params = { "anotherFooBar" })
public Collection<Entry> secondFoo() {
//Do something other
}
}
który działa zgodnie z oczekiwaniami. Po przejściu zły param następujące jest wyjątek:
{
"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
}
Potem stworzył ExceptionHandler
jak widać poniżej:
@ControllerAdvice
public class ExcptionController {
@ResponseStatus(value=HttpStatus.BAD_REQUEST, reason="Invalid parameter")
@ExceptionHandler(UnsatisfiedServletRequestParameterException.class)
private void foo() {
//Log exception
}
}
co podnosi następujący wyjątek:
{
"error": "Bad Request",
"exception": "org.springframework.web.bind.UnsatisfiedServletRequestParameterException",
"message": "Invalid parameter",
"path": "/api/foo",
"status": 400,
"timestamp": 1455287904886
}
Is It można wyłączyć pole wyjątek z reprezentacji JSON
?
Czy @JSONIgnore załatwi sprawę? –