Refactored error handling in mediator.