I guess you can handle declarative exception from Controllers
but Filters
. You can use response instead to send the error code
class AuthorizationFilters {
def filters = {
auth(controller: 'error', invert: true) {
before = {
if(1){ //If auth fails
response.sendError(403)
//render(status: 403) //or
//redirect(controller: 'error', action: 'status403') //or
}
return false
}
}
}
}
Above logic will render the response from ErrorController's status403
action based on the UrlMapping
that is provided in the question
Make sure you are excluding error
controller from filters.