Moved controller error handling into the render method to avoid double renders of layouts.