In a Spring Boot API Rest app I have a ExceptionHandler
for a given RestController
. This controller has a @RequestBody
anotation that is a String
in one of its methods.
@RestController
public class FooController {
@PostMapping("/my_url")
public ResponseEntity myMethod(@RequestBody String param) {
....
}
@ExceptionHandler({MyCustomException.class})
public ResponseEntity handleMyCustomException(MyCustomException ex) {
...
}
}
I'm not able to access the aforementioned String
in the @ExceptionHandler
method (that corresponds to the body of the POST
petition as the title says)
I can set the param
variable in the WebRequest
and then retrieve it the handle
method but this seems a very hacky way to achieve it.
Is there a solution provided by the framework to access the body of the POST
petition in a ExceptionHandler
?