improve stream error catch