Send back error when access denied

This commit is contained in:
Girish Ramakrishnan
2019-09-19 15:24:21 -07:00
parent b05a9ce064
commit 8980c18deb
+6 -5
View File
@@ -7,7 +7,7 @@ exports = module.exports = {
update: update,
del: del,
getDnsRecord: getDnsRecord,
getDnsRecords: getDnsRecords,
verifyDomainLock: verifyDomainLock
};
@@ -155,17 +155,18 @@ function del(req, res, next) {
});
}
function getDnsRecord(req, res, next) {
function getDnsRecords(req, res, next) {
assert.strictEqual(typeof req.params.domains, 'string');
if (!('subdomain' in req.query)) return next(new HttpError(400, 'subdomain is required'));
if (!('type' in req.query)) return next(new HttpError(400, 'type is required'));
domains.getDnsRecords(req.query.subdomain, req.params.domain, req.query.type, function (error, result) {
if (error && error.reason === DomainsError.NOT_FOUND) return next(new HttpError(404, error.message));
domains.getDnsRecords(req.query.subdomain, req.params.domain, req.query.type, function (error, values) {
if (error && error.reason === DomainsError.NOT_FOUND) return next(new HttpError(404, error.message)); // domain (and not record!) not found
if (error && error.reason === DomainsError.EXTERNAL_ERROR) return next(new HttpError(424, error.message));
if (error && error.reason === DomainsError.ACCESS_DENIED) return next(new HttpSuccess(200, { error: { reason: error.reason, message: error.message }}));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, result));
next(new HttpSuccess(200, { values })); // empty array when no dns record
});
}