Improve error handling in tcp transport