add error handler to trap stream errors properly.