Fix assert

NETWORK_ERROR is usually an AggregateError which causes an
assert in BoxError
This commit is contained in:
Girish Ramakrishnan
2024-11-19 17:08:19 +05:30
parent e35b36643c
commit 5e3857fd3d
15 changed files with 69 additions and 68 deletions

View File

@@ -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);
}
}