Only emit an 'error' when socket closed by an error

I added a condition on 'close' listener to only emit 'error' message
when the socket has been closed by an error