handle errors on a socket write