error handling wrapped around socket communication