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

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