diff --git a/src/dns/cloudflare.js b/src/dns/cloudflare.js index 661869ff9..00a799f36 100644 --- a/src/dns/cloudflare.js +++ b/src/dns/cloudflare.js @@ -28,7 +28,7 @@ function translateRequestError(result, callback) { if (result.statusCode === 422) return callback(new DomainsError(DomainsError.BAD_FIELD, result.body.message)); if ((result.statusCode === 400 || result.statusCode === 401 || result.statusCode === 403) && result.body.errors.length > 0) { let error = result.body.errors[0]; - let message = error.message; + let message = `message: ${error.message} statusCode: ${result.statusCode} code:${error.code}`; if (error.code === 6003) { if (error.error_chain[0] && error.error_chain[0].code === 6103) message = 'Invalid API Key'; else message = 'Invalid credentials'; diff --git a/src/mail.js b/src/mail.js index 4c1c7ef4a..40f35a3b0 100644 --- a/src/mail.js +++ b/src/mail.js @@ -625,7 +625,7 @@ function txtRecordsWithSpf(domain, callback) { assert.strictEqual(typeof callback, 'function'); domains.getDnsRecords('', domain, 'TXT', function (error, txtRecords) { - if (error) return callback(error); + if (error) return new MailError(MailError.EXTERNAL_ERROR, error.message); debug('txtRecordsWithSpf: current txt records - %j', txtRecords); @@ -741,10 +741,14 @@ function setDnsRecords(domain, callback) { async.mapSeries(records, function (record, iteratorCallback) { domains.upsertDnsRecords(record.subdomain, record.domain, record.type, record.values, iteratorCallback); }, function (error, changeIds) { - if (error) debug('addDnsRecords: failed to update : %s. will retry', error); - else debug('addDnsRecords: records %j added with changeIds %j', records, changeIds); + if (error) { + debug(`addDnsRecords: failed to update: ${error}`); + return callback(new MailError(MailError.EXTERNAL_ERROR, error.message)); + } - callback(error); + debug('addDnsRecords: records %j added with changeIds %j', records, changeIds); + + callback(null); }); }); }); diff --git a/src/routes/mail.js b/src/routes/mail.js index 0063160d3..2cd35b562 100644 --- a/src/routes/mail.js +++ b/src/routes/mail.js @@ -88,6 +88,7 @@ function setDnsRecords(req, res, next) { mail.setDnsRecords(req.params.domain, function (error) { if (error && error.reason === MailError.NOT_FOUND) return next(new HttpError(404, error.message)); + if (error && error.reason === MailError.EXTERNAL_ERROR) return next(new HttpError(503, error.message)); if (error) return next(new HttpError(500, error)); next(new HttpSuccess(201));