Refactored route error handling