Added proper error handling for socket.getaddrinfo()