0

I have some code like this

@Controller
class SomeController


@GetMapping("/someAsync")
@ResponseBody
public String someAsync() {
    throw new SomeException();
}

@GetMapping("/somePage")
public String somePage() {
    throw new SomeException();
}

in this case, i want to redirect to default error page for "/somePage"

and I need to response like { HttpStatus:500, message: "something happened" }

I made this ControllerAdvice

@ControllerAdvice
class SomeAdvice 

@ExceptionHandler(Exception.class)
@ResponseBody
public Object handle(Exception e) {
    // in this method, I want to know this Exception was called by a method that contains "@ResponseBody"
}

Could I know the method signature like this way?

FirePizza
  • 31
  • 2
  • or is there any way to redirect error page for page request and response Object body for @ResponseBody request when Exception occured? – FirePizza Nov 01 '21 at 06:59
  • Instead of the annotation maybe you could use the method name instead. https://stackoverflow.com/questions/47922306/how-to-find-controller-name-in-controlleradvice-or-restcontrolleradvice-in-spr – dope Nov 01 '21 at 08:14

0 Answers0