Refactored error handling in view