use error codes to detect connection loss