In my controller I do a permissions check to see if the user can do the certain action. If they can't, I'd like to return a 404.
How do I tell Spring to return a 404?
You can throw an exception and handle it in a controller-level method:
@Controller
public class MyController {
@ResponseStatus(NOT_FOUND)
@ExceptionHandler({UnauthorizedException.class})
public void handle() {
// ...
}
}
If any controller method throw a UnauthorizedException.
, the above handler method will be invoked to handle it and return a 404 error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With