added error handling for ECONNREST