SysInfo.EXTERNAL_ERROR is undefined
This commit is contained in:
@@ -17,14 +17,14 @@ function getPublicIp(callback) {
|
||||
superagent.get('http://169.254.169.254/metadata/v1.json').timeout(30 * 1000).end(function (error, result) {
|
||||
if (error || result.statusCode !== 200) {
|
||||
console.error('Error getting metadata', error);
|
||||
return callback(new SysInfoError(SysInfoError.INTERNAL_ERROR, 'Could not detect public IP from metadata'));
|
||||
return callback(new SysInfoError(SysInfoError.EXTERNAL_ERROR, 'Could not detect public IP from metadata'));
|
||||
}
|
||||
|
||||
// Note that we do not use a floating IP for 3 reasons:
|
||||
// The PTR record is not set to floating IP, the outbound interface is not changeable to floating IP
|
||||
// and there are reports that port 25 on floating IP is blocked.
|
||||
var ip = safe.query(result.body, 'interfaces.public[0].ipv4.ip_address');
|
||||
if (!ip) return callback(new SysInfoError(SysInfoError.INTERNAL_ERROR, 'Could not detect public IP from interface'));
|
||||
if (!ip) return callback(new SysInfoError(SysInfoError.EXTERNAL_ERROR, 'Could not detect public IP from interface'));
|
||||
|
||||
callback(null, ip);
|
||||
});
|
||||
|
||||
@@ -19,11 +19,11 @@ function getPublicIp(callback) {
|
||||
superagent.get(config.apiServerOrigin() + '/api/v1/helper/public_ip').timeout(30 * 1000).end(function (error, result) {
|
||||
if (error || result.statusCode !== 200) {
|
||||
console.error('Error getting IP', error);
|
||||
return callback(new SysInfoError(SysInfoError.INTERNAL_ERROR, 'Unable to contact api server'));
|
||||
return callback(new SysInfoError(SysInfoError.EXTERNAL_ERROR, 'Unable to detect IP. API server unreachable'));
|
||||
}
|
||||
if (!result.body && !result.body.ip) {
|
||||
console.error('Unexpected answer. No "ip" found in response body.', result.body);
|
||||
return callback(new SysInfoError(SysInfoError.INTERNAL_ERROR, 'No IP found in body'));
|
||||
return callback(new SysInfoError(SysInfoError.EXTERNAL_ERROR, 'Unable to detect IP. No IP found in response'));
|
||||
}
|
||||
|
||||
callback(null, result.body.ip);
|
||||
|
||||
@@ -13,7 +13,7 @@ function getPublicIp(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
superagent.get('http://169.254.42.42/conf').timeout(30 * 1000).end(function (error, result) {
|
||||
if (error) return callback(new SysInfoError(SysInfoError.INTERNAL_ERROR, error.status ? 'Request failed: ' + error.status : 'Network failure'));
|
||||
if (error) return callback(new SysInfoError(SysInfoError.EXTERNAL_ERROR, error.status ? 'Request failed: ' + error.status : 'Network failure'));
|
||||
if (result.statusCode !== 200) return callback(new SysInfoError(SysInfoError.EXTERNAL_ERROR, util.format('%s %j', result.status, result.body)));
|
||||
|
||||
var kv = result.text.split('\n').filter(function (line) { return line.startsWith('PUBLIC_IP_ADDRESS='); });
|
||||
|
||||
Reference in New Issue
Block a user