Move SysInfoError to BoxError

This commit is contained in:
Girish Ramakrishnan
2019-10-22 14:09:44 -07:00
parent a7614cef2e
commit 332f2e7c10
4 changed files with 12 additions and 38 deletions

View File

@@ -6,8 +6,8 @@ exports = module.exports = {
var assert = require('assert'),
async = require('async'),
superagent = require('superagent'),
SysInfoError = require('../sysinfo.js').SysInfoError;
BoxError = require('../boxerror.js'),
superagent = require('superagent');
function getPublicIp(callback) {
assert.strictEqual(typeof callback, 'function');
@@ -18,11 +18,11 @@ function getPublicIp(callback) {
superagent.get('https://api.cloudron.io/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.EXTERNAL_ERROR, 'Unable to detect IP. API server unreachable'));
return callback(new BoxError(BoxError.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.EXTERNAL_ERROR, 'Unable to detect IP. No IP found in response'));
return callback(new BoxError(BoxError.EXTERNAL_ERROR, 'Unable to detect IP. No IP found in response'));
}
callback(null, result.body.ip);