Refactored error/success response handling