porkbun: incorrect usage of promises
This commit is contained in:
+7
-6
@@ -38,12 +38,13 @@ function injectPrivateFields(newConfig, currentConfig) {
|
||||
if (newConfig.secretapikey === constants.SECRET_PLACEHOLDER) newConfig.secretapikey = currentConfig.secretapikey;
|
||||
}
|
||||
|
||||
async function createRequest(method, url) {
|
||||
async function createRequest(method, url, data) {
|
||||
assert.strictEqual(typeof method, 'string');
|
||||
assert.strictEqual(typeof url, 'string');
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
|
||||
await timers.setTimeout(3000); // see rate limit note at top of file
|
||||
return superagent(method, url).retry(5).timeout(30 * 1000).ok(() => true);
|
||||
return superagent(method, url).retry(5).timeout(30 * 1000).send(data).ok(() => true);
|
||||
}
|
||||
|
||||
async function getDnsRecords(domainConfig, zoneName, name, type) {
|
||||
@@ -59,7 +60,7 @@ async function getDnsRecords(domainConfig, zoneName, name, type) {
|
||||
apikey: domainConfig.apikey,
|
||||
};
|
||||
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/retrieveByNameType/${zoneName}/${type}/${name}`).send(data));
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/retrieveByNameType/${zoneName}/${type}/${name}`, data));
|
||||
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)}`);
|
||||
@@ -81,7 +82,7 @@ async function delDnsRecords(domainConfig, zoneName, name, type) {
|
||||
};
|
||||
|
||||
// deletes all the records matching type+name
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/deleteByNameType/${zoneName}/${type}/${name}`).send(data));
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/deleteByNameType/${zoneName}/${type}/${name}`, data));
|
||||
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));
|
||||
@@ -120,7 +121,7 @@ async function upsert(domainObject, location, type, values) {
|
||||
data.content = value;
|
||||
}
|
||||
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/create/${zoneName}`).send(data));
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/create/${zoneName}`, data));
|
||||
|
||||
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error);
|
||||
if (response.statusCode !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, formatError(response));
|
||||
@@ -166,7 +167,7 @@ async function del(domainObject, location, type, values) {
|
||||
const ids = records.filter(r => values.includes(r.content)).map(r => r.id);
|
||||
|
||||
for (const id of ids) {
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/delete/${zoneName}/${id}`).send(data));
|
||||
const [error, response] = await safe(createRequest('POST', `${PORKBUN_API}/delete/${zoneName}/${id}`, data));
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user