Node.js TCP socket write - error handling and retry

How to handle the case where socket connection got closed when write just about to finish? I know socket.write() is asynchronous and emit 'error' event when write fails.

But how to handle this gracefully, say I wanted to write the packet/message to another socket or log the packet which fails to write. I don't see 'error' event giving access to the packet which failed to write.

Is there any way?