Added test to cover. Started refactoring some of the app error handling in the process of this. Fixes #2696