diff --git a/src/domaindb.js b/src/domaindb.js index b2e5a1229..e67850b86 100644 --- a/src/domaindb.js +++ b/src/domaindb.js @@ -101,7 +101,13 @@ function del(domain, callback) { assert.strictEqual(typeof callback, 'function'); database.query('DELETE FROM domains WHERE domain=?', [ domain ], function (error, result) { - if (error && error.code === 'ER_ROW_IS_REFERENCED_2') return callback(new BoxError(BoxError.CONFLICT, error.message)); + if (error && error.code === 'ER_ROW_IS_REFERENCED_2') { + if (error.message.indexOf('apps_mailDomain_constraint') !== -1) return callback(new BoxError(BoxError.CONFLICT, 'Domain is in use by an app or the mailbox of an app. Check the domains of apps and the Email section of each app.')); + if (error.message.indexOf('subdomains') !== -1) return callback(new BoxError(BoxError.CONFLICT, 'Domain is in use by one or more app(s).')); + if (error.message.indexOf('mail') !== -1) return callback(new BoxError(BoxError.CONFLICT, 'Domain is in use by one or more mailboxes. Delete them first in the Email view.')); + + return callback(new BoxError(BoxError.CONFLICT, error.message)); + } if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error)); if (result.affectedRows === 0) return callback(new BoxError(BoxError.NOT_FOUND, 'Domain not found')); diff --git a/src/domains.js b/src/domains.js index d0c56e5e8..2271e7627 100644 --- a/src/domains.js +++ b/src/domains.js @@ -309,13 +309,6 @@ function del(domain, auditSource, callback) { if (domain === settings.adminDomain()) return callback(new BoxError(BoxError.CONFLICT, 'Cannot remove admin domain')); domaindb.del(domain, function (error) { - if (error && error.reason === BoxError.CONFLICT) { - if (error.message.indexOf('apps_mailDomain_constraint') !== -1) return callback(new BoxError(BoxError.CONFLICT, 'Domain is in use as the mailbox of an app. Check the Email section of each app.')); - if (error.message.indexOf('subdomains') !== -1) return callback(new BoxError(BoxError.CONFLICT, 'Domain is in use by an app. Move the app first to a different location.')); - if (error.message.indexOf('mail') !== -1) return callback(new BoxError(BoxError.CONFLICT, 'Domain is in use by a mailbox. Delete mailboxes first in the Email view.')); - - // intentional fall through - } if (error) return callback(error); eventlog.add(eventlog.ACTION_DOMAIN_REMOVE, auditSource, { domain });