Handle errors if domain is still used on deletion attempt

This commit is contained in:
Johannes Zellner
2017-11-11 22:02:34 +01:00
parent 53e3626e51
commit de44796b6f
6 changed files with 48 additions and 6 deletions
+3 -3
View File
@@ -49,6 +49,7 @@ DomainError.ALREADY_EXISTS = 'Domain already exists';
DomainError.EXTERNAL_ERROR = 'External error';
DomainError.BAD_FIELD = 'Bad Field';
DomainError.STILL_BUSY = 'Still busy';
DomainError.IN_USE = 'In Use';
DomainError.INTERNAL_ERROR = 'Internal error';
DomainError.ACCESS_DENIED = 'Access denied';
DomainError.INVALID_PROVIDER = 'provider must be route53, gcdns, digitalocean, cloudflare, noop, manual or caas';
@@ -196,10 +197,9 @@ function del(domain, callback) {
assert.strictEqual(typeof domain, 'string');
assert.strictEqual(typeof callback, 'function');
// TODO check if domain is still used by an app
domaindb.del(domain, function (error) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new DomainError(DomainError.NOT_FOUND));
if (error && error.reason === DatabaseError.IN_USE) return callback(new DomainError(DomainError.IN_USE));
if (error) return callback(new DomainError(DomainError.INTERNAL_ERROR, error));
return callback(null);
@@ -283,4 +283,4 @@ function waitForDNSRecord(fqdn, value, type, options, callback) {
api(provider).waitForDns(fqdn, zoneName, value, type, options, callback);
});
}
}