diff --git a/src/dns/bunny.js b/src/dns/bunny.js index e2ec49862..b0888688e 100644 --- a/src/dns/bunny.js +++ b/src/dns/bunny.js @@ -53,7 +53,7 @@ async function getZoneId(domainConfig, zoneName) { .retry(5) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -78,7 +78,7 @@ async function getDnsRecords(domainConfig, zoneName, name, type) { .retry(5) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (!Array.isArray(response.body.Records)) throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid records in response: ${JSON.stringify(response.body)}`); @@ -129,7 +129,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } else { @@ -141,7 +141,7 @@ async function upsert(domainObject, location, type, values) { .ok(() => true)); ++i; - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -198,7 +198,7 @@ async function del(domainObject, location, type, values) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 400) continue; if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/cloudflare.js b/src/dns/cloudflare.js index fd457f1b3..8be523f7c 100644 --- a/src/dns/cloudflare.js +++ b/src/dns/cloudflare.js @@ -75,7 +75,7 @@ async function getZoneByName(domainConfig, zoneName) { assert.strictEqual(typeof zoneName, 'string'); const [error, response] = await safe(createRequest('GET', `${CLOUDFLARE_ENDPOINT}/zones?name=${zoneName}&status=active`, domainConfig)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200 || response.body.success !== true) throw translateRequestError(response); if (!response.body.result || !response.body.result.length) throw new BoxError(BoxError.NOT_FOUND, `${response.statusCode} ${response.text}`); @@ -99,7 +99,7 @@ async function getDnsRecords(domainConfig, zoneId, fqdn, type) { const [error, response] = await safe(createRequest('GET', `${CLOUDFLARE_ENDPOINT}/zones/${zoneId}/dns_records`, domainConfig) .query({ type: type, name: fqdn })); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200 || response.body.success !== true) throw translateRequestError(response); const result = response.body.result; @@ -155,7 +155,7 @@ async function upsert(domainObject, location, type, values) { const [error, response] = await safe(createRequest('POST', `${CLOUDFLARE_ENDPOINT}/zones/${zoneId}/dns_records`, domainConfig) .send(data)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200 || response.body.success !== true) throw translateRequestError(response); } else { // replace existing record data.proxied = records[i].proxied; // preserve proxied parameter @@ -164,7 +164,7 @@ async function upsert(domainObject, location, type, values) { const [error, response] = await safe(createRequest('PUT', `${CLOUDFLARE_ENDPOINT}/zones/${zoneId}/dns_records/${records[i].id}`, domainConfig) .send(data)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200 || response.body.success !== true) throw translateRequestError(response); ++i; // increment, as we have consumed the record } @@ -215,7 +215,7 @@ async function del(domainObject, location, type, values) { for (const r of tmp) { const [error, response] = await safe(createRequest('DELETE', `${CLOUDFLARE_ENDPOINT}/zones/${zoneId}/dns_records/${r.id}`, domainConfig)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200 || response.body.success !== true) throw translateRequestError(response); } } diff --git a/src/dns/desec.js b/src/dns/desec.js index 3932373c2..81d86f868 100644 --- a/src/dns/desec.js +++ b/src/dns/desec.js @@ -54,7 +54,7 @@ async function get(domainObject, location, type) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) return []; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -90,7 +90,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } @@ -112,7 +112,7 @@ async function del(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) return; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/digitalocean.js b/src/dns/digitalocean.js index 5280653ac..29fcad546 100644 --- a/src/dns/digitalocean.js +++ b/src/dns/digitalocean.js @@ -54,7 +54,7 @@ async function getZoneRecords(domainConfig, zoneName, name, type) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) throw new BoxError(BoxError.NOT_FOUND, formatError(response)); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -112,7 +112,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 422) throw new BoxError(BoxError.BAD_FIELD, response.body.message); if (response.statusCode !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -128,7 +128,7 @@ async function upsert(domainObject, location, type, values) { ++i; - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 422) throw new BoxError(BoxError.BAD_FIELD, response.body.message); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -188,7 +188,7 @@ async function del(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) return; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/dnsimple.js b/src/dns/dnsimple.js index 59084c272..a67483a3d 100644 --- a/src/dns/dnsimple.js +++ b/src/dns/dnsimple.js @@ -43,7 +43,7 @@ async function getAccountId(domainConfig) { .retry(5) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -62,7 +62,7 @@ async function getZone(domainConfig, zoneName) { .retry(5) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -87,7 +87,7 @@ async function getDnsRecords(domainConfig, zoneName, name, type) { .retry(5) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (!Array.isArray(response.body.data)) throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid data in response: ${JSON.stringify(response.body)}`); @@ -138,7 +138,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); recordIds.push(safe.query(response.body, 'data.id')); @@ -151,7 +151,7 @@ async function upsert(domainObject, location, type, values) { .ok(() => true)); ++i; - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); recordIds.push(safe.query(response.body, 'data.id')); @@ -207,7 +207,7 @@ async function del(domainObject, location, type, values) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 404) continue; if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/gandi.js b/src/dns/gandi.js index 183bf385e..2a4b06c37 100644 --- a/src/dns/gandi.js +++ b/src/dns/gandi.js @@ -74,7 +74,7 @@ async function upsert(domainObject, location, type, values) { const [error, response] = await safe(createRequest('PUT', `${GANDI_API}/domains/${zoneName}/records/${name}/${type}`, domainConfig) .send(data)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response)); if (response.statusCode !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -93,7 +93,7 @@ async function get(domainObject, location, type) { const [error, response] = await safe(createRequest('GET', `${GANDI_API}/domains/${zoneName}/records/${name}/${type}`, domainConfig)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 404) return []; if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -115,7 +115,7 @@ async function del(domainObject, location, type, values) { const [error, response] = await safe(createRequest('DELETE', `${GANDI_API}/domains/${zoneName}/records/${name}/${type}`, domainConfig)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) return; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/godaddy.js b/src/dns/godaddy.js index bc27104a0..a69ea9d79 100644 --- a/src/dns/godaddy.js +++ b/src/dns/godaddy.js @@ -69,7 +69,7 @@ async function upsert(domainObject, location, type, values) { .send(records) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response)); // no such zone if (response.statusCode === 422) throw new BoxError(BoxError.BAD_FIELD, formatError(response)); // conflict @@ -92,7 +92,7 @@ async function get(domainObject, location, type) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 404) return []; if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -138,7 +138,7 @@ async function del(domainObject, location, type, values) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) return; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/hetzner.js b/src/dns/hetzner.js index ed39114f8..8049d3d83 100644 --- a/src/dns/hetzner.js +++ b/src/dns/hetzner.js @@ -45,7 +45,7 @@ async function getZone(domainConfig, zoneName) { .timeout(30 * 1000) .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 401 || response.statusCode === 403) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -77,7 +77,7 @@ async function getZoneRecords(domainConfig, zone, name, type) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) throw new BoxError(BoxError.NOT_FOUND, formatError(response)); if (response.statusCode === 401 || response.statusCode === 403) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -104,7 +104,7 @@ async function upsert(domainObject, location, type, values) { zoneName = domainObject.zoneName, name = dns.getName(domainObject, location, type) || '@'; - debug('upsert: %s for zone %s of type %s with values %j', name, zoneName, type, values); + debug(`upsert: ${name} for zone ${zoneName} of type ${type} with values ${JSON.stringify(values)}`); const zone = await getZone(domainConfig, zoneName); const records = await getZoneRecords(domainConfig, zone, name, type); @@ -112,7 +112,7 @@ async function upsert(domainObject, location, type, values) { // used to track available records to update instead of create let i = 0; - for (let value of values) { + for (const value of values) { const data = { type, name, @@ -129,7 +129,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 422) throw new BoxError(BoxError.BAD_FIELD, response.body.message); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -143,7 +143,7 @@ async function upsert(domainObject, location, type, values) { ++i; - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode === 422) throw new BoxError(BoxError.BAD_FIELD, response.body.message); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -202,7 +202,7 @@ async function del(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) return; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/linode.js b/src/dns/linode.js index f1e501f15..08c38c9ed 100644 --- a/src/dns/linode.js +++ b/src/dns/linode.js @@ -47,7 +47,7 @@ async function getZoneId(domainConfig, zoneName) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -84,7 +84,7 @@ async function getZoneRecords(domainConfig, zoneName, name, type) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) throw new BoxError(BoxError.NOT_FOUND, formatError(response)); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -153,7 +153,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response)); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -167,7 +167,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response)); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -211,7 +211,7 @@ async function del(domainObject, location, type, values) { .timeout(30 * 1000) .retry(5) .ok(() => true)); - if (error && !error.response) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error && !error.response) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) return; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/dns/namecheap.js b/src/dns/namecheap.js index 183e17ca4..95e07812b 100644 --- a/src/dns/namecheap.js +++ b/src/dns/namecheap.js @@ -61,7 +61,7 @@ async function getZone(domainConfig, zoneName) { query.TLD = zoneName.slice(query.SLD.length + 1); const [error, response] = await safe(superagent.get(ENDPOINT).query(query).ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); const parser = new xml2js.Parser(); const [parserError, result] = await safe(util.promisify(parser.parseString)(response.text)); diff --git a/src/dns/namecom.js b/src/dns/namecom.js index acada72fc..da08b3abe 100644 --- a/src/dns/namecom.js +++ b/src/dns/namecom.js @@ -55,7 +55,7 @@ async function addRecord(domainConfig, zoneName, name, type, values) { data.answer = values[0].split(' ')[1]; } else if (type === 'TXT') { // we have to strip the quoting for some odd reason for name.com! If you change that also change updateRecord - let tmp = values[0]; + const tmp = values[0]; data.answer = tmp.indexOf('"') === 0 && tmp.lastIndexOf('"') === tmp.length-1 ? tmp.slice(1, tmp.length-1) : tmp; } else { data.answer = values[0]; @@ -67,7 +67,7 @@ async function addRecord(domainConfig, zoneName, name, type, values) { .send(data) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } @@ -93,7 +93,7 @@ async function updateRecord(domainConfig, zoneName, recordId, name, type, values data.answer = values[0].split(' ')[1]; } else if (type === 'TXT') { // we have to strip the quoting for some odd reason for name.com! If you change that also change addRecord - let tmp = values[0]; + const tmp = values[0]; data.answer = tmp.indexOf('"') === 0 && tmp.lastIndexOf('"') === tmp.length-1 ? tmp.slice(1, tmp.length-1) : tmp; } else { data.answer = values[0]; @@ -105,7 +105,7 @@ async function updateRecord(domainConfig, zoneName, recordId, name, type, values .send(data) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } @@ -123,7 +123,7 @@ async function getInternal(domainConfig, zoneName, name, type) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -194,7 +194,7 @@ async function del(domainObject, location, type, values) { .auth(domainConfig.username, domainConfig.token) .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 403) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } diff --git a/src/dns/netcup.js b/src/dns/netcup.js index bd6434a19..b8376dd8d 100644 --- a/src/dns/netcup.js +++ b/src/dns/netcup.js @@ -51,7 +51,7 @@ async function login(domainConfig) { }; const [error, response] = await safe(superagent.post(API_ENDPOINT).send(data).ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (!response.body.responsedata.apisessionid) throw new BoxError(BoxError.ACCESS_DENIED, 'invalid api password'); @@ -76,7 +76,7 @@ async function getAllRecords(domainConfig, apiSessionId, zoneName) { }; const [error, response] = await safe(superagent.post(API_ENDPOINT).send(data).ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); return response.body.responsedata.dnsrecords || []; @@ -98,7 +98,7 @@ async function upsert(domainObject, location, type, values) { const result = await getAllRecords(domainConfig, apiSessionId, zoneName); - let records = []; + const records = []; values.forEach(function (value) { // remove possible quotation @@ -134,7 +134,7 @@ async function upsert(domainObject, location, type, values) { }; const [error, response] = await safe(superagent.post(API_ENDPOINT).send(data).ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (response.body.statuscode !== 2000) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } @@ -174,14 +174,14 @@ async function del(domainObject, location, type, values) { const result = await getAllRecords(domainConfig, apiSessionId, zoneName); - let records = []; + const records = []; values.forEach(function (value) { // remove possible quotation if (value.charAt(0) === '"') value = value.slice(1); if (value.charAt(value.length -1) === '"') value = value.slice(0, -1); - let record = result.find(function (r) { return r.hostname === name && r.type === type && r.destination === value; }); + const record = result.find(function (r) { return r.hostname === name && r.type === type && r.destination === value; }); if (!record) return; record.deleterecord = true; @@ -205,7 +205,7 @@ async function del(domainObject, location, type, values) { }; const [error, response] = await safe(superagent.post(API_ENDPOINT).send(data).ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (response.body.statuscode !== 2000) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); } diff --git a/src/dns/porkbun.js b/src/dns/porkbun.js index 339f22a50..9ffc5c050 100644 --- a/src/dns/porkbun.js +++ b/src/dns/porkbun.js @@ -57,7 +57,7 @@ async function getDnsRecords(domainConfig, zoneName, name, type) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (response.body.status !== 'SUCCESS') throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid status in response: ${JSON.stringify(response.body)}`); if (!Array.isArray(response.body.records)) throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid records in response: ${JSON.stringify(response.body)}`); @@ -84,7 +84,7 @@ async function delDnsRecords(domainConfig, zoneName, name, type) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 400) return; // not found, "Could not delete record." if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (response.body.status !== 'SUCCESS') throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid status in response: ${JSON.stringify(response.body)}`); @@ -128,7 +128,7 @@ async function upsert(domainObject, location, type, values) { .send(data) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (response.body.status !== 'SUCCESS') throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid status in response: ${JSON.stringify(response.body)}`); if (!response.body.id) throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid id in response: ${JSON.stringify(response.body)}`); @@ -180,7 +180,7 @@ async function del(domainObject, location, type, values) { .timeout(30 * 1000) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 400) continue; // not found! "Invalid record id." if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); if (response.body.status !== 'SUCCESS') throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid status in response: ${JSON.stringify(response.body)}`); diff --git a/src/dns/vultr.js b/src/dns/vultr.js index 1d1202cac..f2409f616 100644 --- a/src/dns/vultr.js +++ b/src/dns/vultr.js @@ -44,14 +44,14 @@ async function getZoneRecords(domainConfig, zoneName, name, type) { debug(`getInternal: getting dns records of ${zoneName} with ${name} and type ${type}`); - let per_page = 100, cursor = null; - let records = []; + const per_page = 100; + let cursor = null, records = []; do { const url = `${VULTR_ENDPOINT}/domains/${zoneName}/records?per_page=${per_page}` + (cursor ? `&cursor=${cursor}` : ''); const [error, response] = await safe(superagent.get(url).set('Authorization', 'Bearer ' + domainConfig.token).timeout(30 * 1000).retry(5).ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) throw new BoxError(BoxError.NOT_FOUND, formatError(response)); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -94,7 +94,8 @@ async function upsert(domainObject, location, type, values) { const records = await getZoneRecords(domainConfig, zoneName, name, type); - let i = 0, recordIds = []; // used to track available records to update instead of create + let i = 0; + const recordIds = []; // used to track available records to update instead of create for (const value of values) { const data = { @@ -121,7 +122,7 @@ async function upsert(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response)); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -137,7 +138,7 @@ async function upsert(domainObject, location, type, values) { ++i; - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response)); if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); @@ -181,7 +182,7 @@ async function del(domainObject, location, type, values) { .retry(5) .ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.statusCode === 404) continue; if (response.statusCode === 403 || response.statusCode === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response)); if (response.statusCode !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response)); diff --git a/src/graphs.js b/src/graphs.js index 2ec88855d..e31c06102 100644 --- a/src/graphs.js +++ b/src/graphs.js @@ -62,7 +62,7 @@ async function getContainerStats(name, fromMinutes, noNullPoints) { }; const [error, response] = await safe(superagent.get(graphiteUrl).query(query).timeout(30 * 1000).ok(() => true)); - if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message); + if (error) throw new BoxError(BoxError.NETWORK_ERROR, error); if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Unknown error with ${target}: ${response.status} ${response.text}`); results.push(response.body[0] && response.body[0].datapoints ? response.body[0].datapoints : []); @@ -102,7 +102,7 @@ async function getSystem(fromMinutes, noNullPoints) { }; const [memCpuError, memCpuResponse] = await safe(superagent.get(graphiteUrl).query(query).timeout(30 * 1000).ok(() => true)); - if (memCpuError) throw new BoxError(BoxError.NETWORK_ERROR, memCpuError.message); + if (memCpuError) throw new BoxError(BoxError.NETWORK_ERROR, memCpuError); if (memCpuResponse.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Unknown error: ${memCpuResponse.status} ${memCpuResponse.text}`); const appResponses = {};