Is there an exception or something else that can be raised from a service (or other non-Controller method) that will interrupt the current response handling and return a 404 to the user?
In the Django world, there is get_object_or_404
which raises a Http404
exception which has this effect. I'm writing service; if that service determines that the object requested is not accessible to the user (in this case it's not published yet), I would like it to trigger a 404 and stop the remainder of the execution. The goals is for the controllers calling the service to be DRY and not always repeat the def obj = someService.getSomething(); if (obj) {} else { render status: 404}
call.
Summary:
In Django, I can raise a Http404
at any point to stop request processing and return a 404. Is there an equivalent or a way to do this in Grails NOT from a controller?