Refactor error_response