Spring MVC Exception Handling

You may also like...

Subscribe
Notify of
guest
4 Comments
Oldest
Newest
Inline Feedbacks
View all comments
rubn
rubn
February 20, 2018 17:43

Hi,

How are you? good tutorial, would there be the possibility of redirecting to an external url in case of error 4xx, 5xx ?

rubn
rubn
February 20, 2018 20:43
Reply to  MemoryNotFound

Thanks a lot my homie

@RestController
public class ControlerRedirect implements ErrorController {

    private static final String GOOGLE = "http://www.google.com";

    @ExceptionHandler(RuntimeException.class)
    @RequestMapping(method=RequestMethod.GET)
    public void handle(RuntimeException ex, HttpServletResponse hsp) throws IOException {
        hsp.sendRedirect(GOOGLE);
    }

    @Override
    public String getErrorPath() {
        return "Redirect now";
    }
}
4
0
Would love your thoughts, please comment.x
()
x