Added a check for error code returned from the request.get function. Otherwise when there is a connection error there is a problem with request.statusCode as request is null.