I have a @ControllerAdvice class which captures various types of custom Exceptions. The problem is, these custom exceptions can be thrown my various methods within the Controller.
So in my @ControllerAdvice class, when it's time to Splunk the Exception, I need to know what specific action was going on, in order to put the proper code in my Splunk log.
For example:
@RestController
@RequestMapping(value = "/person/{id}")
public class PersonController {
public ResponseEntity<PersonDto> getPerson(@PathVariable final String id) throws PersonNotFoundException {
public ResponseEntity<PersonStuffDto> getPersonStuff(@PathVariable final String id) throws PersonNotFoundException {
... and my advice:
@ControllerAdvice
public class PersonControllerExceptionHandler {
@ExceptionHandler(PersonNotFoundException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseBody
public ErrorResponse personNotFoundException (final PersonNotFoundException exception, final HttpServletRequest request) {
... Splunk ...
}
Within the personNotFoundException() method, I need to Splunk either "RETRIEVING_PERSON" code, or a "RETRIEVING_PERSON_STUFF" code.
How can I distinguish the source of the Exception? Do I have to inspect the request ... look at the url or something? And if so ... woudldn't it just be easier to leave the Exception handling, or at least this part of it, in the Controller itself?