refactor streaming error handling