remove usage of util.format
This commit is contained in:
@@ -19,7 +19,6 @@ const assert = require('assert'),
|
|||||||
ipaddr = require('ipaddr.js'),
|
ipaddr = require('ipaddr.js'),
|
||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
util = require('util'),
|
|
||||||
waitForDns = require('./waitfordns.js'),
|
waitForDns = require('./waitfordns.js'),
|
||||||
_ = require('underscore');
|
_ = require('underscore');
|
||||||
|
|
||||||
@@ -38,20 +37,20 @@ function injectPrivateFields(newConfig, currentConfig) {
|
|||||||
function translateRequestError(result) {
|
function translateRequestError(result) {
|
||||||
assert.strictEqual(typeof result, 'object');
|
assert.strictEqual(typeof result, 'object');
|
||||||
|
|
||||||
if (result.statusCode === 404) return new BoxError(BoxError.NOT_FOUND, util.format('%s %j', result.statusCode, 'API does not exist'));
|
if (result.statusCode === 404) return new BoxError(BoxError.NOT_FOUND, `[${result.statusCode}] ${JSON.stringify(result.body)}`);
|
||||||
if (result.statusCode === 422) return new BoxError(BoxError.BAD_FIELD, result.body.message);
|
if (result.statusCode === 422) return new BoxError(BoxError.BAD_FIELD, result.body.message);
|
||||||
if (result.statusCode === 400 || result.statusCode === 401 || result.statusCode === 403) {
|
if (result.statusCode === 400 || result.statusCode === 401 || result.statusCode === 403) {
|
||||||
let message = 'Unknown error';
|
let message = 'Unknown error';
|
||||||
if (typeof result.body.error === 'string') {
|
if (typeof result.body.error === 'string') {
|
||||||
message = `message: ${result.body.error} statusCode: ${result.statusCode}`;
|
message = `[${result.statusCode}] ${result.body.error}`;
|
||||||
} else if (Array.isArray(result.body.errors) && result.body.errors.length > 0) {
|
} else if (Array.isArray(result.body.errors) && result.body.errors.length > 0) {
|
||||||
const error = result.body.errors[0];
|
const error = result.body.errors[0];
|
||||||
message = `message: ${error.message} statusCode: ${result.statusCode} code:${error.code}`;
|
message = `[${result.statusCode}] ${error.message} code:${error.code}`;
|
||||||
}
|
}
|
||||||
return new BoxError(BoxError.ACCESS_DENIED, message);
|
return new BoxError(BoxError.ACCESS_DENIED, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BoxError(BoxError.EXTERNAL_ERROR, util.format('%s %j', result.statusCode, result.body));
|
return new BoxError(BoxError.EXTERNAL_ERROR, `${result.statusCode} ${JSON.stringify(result.body)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRequest(method, url, domainConfig) {
|
function createRequest(method, url, domainConfig) {
|
||||||
|
|||||||
+1
-2
@@ -19,13 +19,12 @@ const assert = require('assert'),
|
|||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
timers = require('timers/promises'),
|
timers = require('timers/promises'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
util = require('util'),
|
|
||||||
waitForDns = require('./waitfordns.js');
|
waitForDns = require('./waitfordns.js');
|
||||||
|
|
||||||
const DESEC_ENDPOINT = 'https://desec.io/api/v1';
|
const DESEC_ENDPOINT = 'https://desec.io/api/v1';
|
||||||
|
|
||||||
function formatError(response) {
|
function formatError(response) {
|
||||||
return util.format('deSEC DNS error [%s] %j', response.statusCode, response.body);
|
return `deSEC DNS error [${response.statusCode}] ${JSON.stringify(response.body)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePrivateFields(domainObject) {
|
function removePrivateFields(domainObject) {
|
||||||
|
|||||||
+1
-2
@@ -18,13 +18,12 @@ const assert = require('assert'),
|
|||||||
dns = require('../dns.js'),
|
dns = require('../dns.js'),
|
||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
util = require('util'),
|
|
||||||
waitForDns = require('./waitfordns.js');
|
waitForDns = require('./waitfordns.js');
|
||||||
|
|
||||||
const GANDI_API = 'https://dns.api.gandi.net/api/v5';
|
const GANDI_API = 'https://dns.api.gandi.net/api/v5';
|
||||||
|
|
||||||
function formatError(response) {
|
function formatError(response) {
|
||||||
return util.format(`Gandi DNS error [${response.statusCode}] ${response.body.message}`);
|
return `Gandi DNS error [${response.statusCode}] ${response.body.message}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePrivateFields(domainObject) {
|
function removePrivateFields(domainObject) {
|
||||||
|
|||||||
+1
-2
@@ -18,14 +18,13 @@ const assert = require('assert'),
|
|||||||
dns = require('../dns.js'),
|
dns = require('../dns.js'),
|
||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
util = require('util'),
|
|
||||||
waitForDns = require('./waitfordns.js');
|
waitForDns = require('./waitfordns.js');
|
||||||
|
|
||||||
// const GODADDY_API_OTE = 'https://api.ote-godaddy.com/v1/domains';
|
// const GODADDY_API_OTE = 'https://api.ote-godaddy.com/v1/domains';
|
||||||
const GODADDY_API = 'https://api.godaddy.com/v1/domains';
|
const GODADDY_API = 'https://api.godaddy.com/v1/domains';
|
||||||
|
|
||||||
function formatError(response) {
|
function formatError(response) {
|
||||||
return util.format(`GoDaddy DNS error [${response.statusCode}] ${response.body.message}`);
|
return `GoDaddy DNS error [${response.statusCode}] ${response.body.message}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePrivateFields(domainObject) {
|
function removePrivateFields(domainObject) {
|
||||||
|
|||||||
+3
-3
@@ -18,13 +18,12 @@ const assert = require('assert'),
|
|||||||
dns = require('../dns.js'),
|
dns = require('../dns.js'),
|
||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
util = require('util'),
|
|
||||||
waitForDns = require('./waitfordns.js');
|
waitForDns = require('./waitfordns.js');
|
||||||
|
|
||||||
const LINODE_ENDPOINT = 'https://api.linode.com/v4';
|
const LINODE_ENDPOINT = 'https://api.linode.com/v4';
|
||||||
|
|
||||||
function formatError(response) {
|
function formatError(response) {
|
||||||
return util.format('Linode DNS error [%s] %j', response.statusCode, response.body);
|
return `Linode DNS error [${response.statusCode}] ${JSON.stringify(response.body)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePrivateFields(domainObject) {
|
function removePrivateFields(domainObject) {
|
||||||
@@ -126,7 +125,8 @@ async function upsert(domainObject, location, type, values) {
|
|||||||
debug('upsert: %s for zone %s of type %s with values %j', name, zoneName, type, values);
|
debug('upsert: %s for zone %s of type %s with values %j', name, zoneName, type, values);
|
||||||
|
|
||||||
const { zoneId, records } = await getZoneRecords(domainConfig, zoneName, name, type);
|
const { zoneId, records } = await getZoneRecords(domainConfig, zoneName, name, type);
|
||||||
let i = 0, recordIds = []; // used to track available records to update instead of create
|
let i = 0; // used to track available records to update instead of create
|
||||||
|
const recordIds = [];
|
||||||
|
|
||||||
for (const value of values) {
|
for (const value of values) {
|
||||||
const data = {
|
const data = {
|
||||||
|
|||||||
+2
-3
@@ -18,14 +18,13 @@ const assert = require('assert'),
|
|||||||
dns = require('../dns.js'),
|
dns = require('../dns.js'),
|
||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
util = require('util'),
|
|
||||||
waitForDns = require('./waitfordns.js');
|
waitForDns = require('./waitfordns.js');
|
||||||
|
|
||||||
const API_ENDPOINT = 'https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON';
|
const API_ENDPOINT = 'https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON';
|
||||||
|
|
||||||
function formatError(response) {
|
function formatError(response) {
|
||||||
if (response.body) return util.format('Netcup DNS error [%s] %s', response.body.statuscode, response.body.longmessage);
|
if (response.body) return `Netcup DNS error [${response.body.statuscode}] ${response.body.longmessage}`;
|
||||||
else return util.format('Netcup DNS error [%s] %s', response.statusCode, response.text);
|
else return `Netcup DNS error [${response.statusCode}] ${response.text}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePrivateFields(domainObject) {
|
function removePrivateFields(domainObject) {
|
||||||
|
|||||||
+1
-2
@@ -18,13 +18,12 @@ const assert = require('assert'),
|
|||||||
dns = require('../dns.js'),
|
dns = require('../dns.js'),
|
||||||
safe = require('safetydance'),
|
safe = require('safetydance'),
|
||||||
superagent = require('superagent'),
|
superagent = require('superagent'),
|
||||||
util = require('util'),
|
|
||||||
waitForDns = require('./waitfordns.js');
|
waitForDns = require('./waitfordns.js');
|
||||||
|
|
||||||
const VULTR_ENDPOINT = 'https://api.vultr.com/v2';
|
const VULTR_ENDPOINT = 'https://api.vultr.com/v2';
|
||||||
|
|
||||||
function formatError(response) {
|
function formatError(response) {
|
||||||
return util.format('Vultr DNS error [%s] %j', response.statusCode, response.body);
|
return `Vultr DNS error [${response.statusCode}] ${JSON.stringify(response.body)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removePrivateFields(domainObject) {
|
function removePrivateFields(domainObject) {
|
||||||
|
|||||||
Reference in New Issue
Block a user