Here is a gist where you don't use exceptions to return non 200 responses:
A few things to note from this snippet:
- This is a Spring Boot implementation (Boot makes things so much simple)
- The HttpServletResponse is injected by Boot (Spring MVC), no need of additional setup.
- Notice that the body return is null already, so the non 200 response makes more sense.