replace with custom superagent based on fetch API
This commit is contained in:
+14
-14
@@ -17,13 +17,13 @@ const assert = require('assert'),
|
||||
dig = require('../dig.js'),
|
||||
dns = require('../dns.js'),
|
||||
safe = require('safetydance'),
|
||||
superagent = require('superagent'),
|
||||
superagent = require('../superagent.js'),
|
||||
waitForDns = require('./waitfordns.js');
|
||||
|
||||
const VULTR_ENDPOINT = 'https://api.vultr.com/v2';
|
||||
|
||||
function formatError(response) {
|
||||
return `Vultr DNS error [${response.statusCode}] ${JSON.stringify(response.body)}`;
|
||||
return `Vultr DNS error [${response.status}] ${response.text}`;
|
||||
}
|
||||
|
||||
function removePrivateFields(domainObject) {
|
||||
@@ -51,9 +51,9 @@ async function getZoneRecords(domainConfig, zoneName, name, type) {
|
||||
|
||||
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);
|
||||
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));
|
||||
if (response.status === 404) throw new BoxError(BoxError.NOT_FOUND, formatError(response));
|
||||
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
|
||||
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
|
||||
|
||||
records = records.concat(response.body.records.filter(function (record) {
|
||||
return (record.type === type && record.name === name);
|
||||
@@ -122,9 +122,9 @@ async function upsert(domainObject, location, type, values) {
|
||||
.ok(() => true));
|
||||
|
||||
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));
|
||||
if (response.status === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response));
|
||||
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
|
||||
if (response.status !== 201) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
|
||||
|
||||
recordIds.push(response.body.record.id);
|
||||
} else {
|
||||
@@ -138,9 +138,9 @@ async function upsert(domainObject, location, type, values) {
|
||||
++i;
|
||||
|
||||
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));
|
||||
if (response.status === 400) throw new BoxError(BoxError.BAD_FIELD, formatError(response));
|
||||
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
|
||||
if (response.status !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
|
||||
|
||||
recordIds.push(records[i-1].id);
|
||||
}
|
||||
@@ -182,9 +182,9 @@ async function del(domainObject, location, type, values) {
|
||||
.ok(() => true));
|
||||
|
||||
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));
|
||||
if (response.status === 404) continue;
|
||||
if (response.status === 403 || response.status === 401) throw new BoxError(BoxError.ACCESS_DENIED, formatError(response));
|
||||
if (response.status !== 204) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user