moved and improved app error handling to the controller