diff --git a/src/domaindb.js b/src/domaindb.js index 3221f11ee..b2e5a1229 100644 --- a/src/domaindb.js +++ b/src/domaindb.js @@ -101,7 +101,7 @@ 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)); + if (error && error.code === 'ER_ROW_IS_REFERENCED_2') 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 fd628edd0..d0c56e5e8 100644 --- a/src/domains.js +++ b/src/domains.js @@ -309,7 +309,13 @@ 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) return callback(new BoxError(BoxError.CONFLICT, 'Could not remove domain. Check if this domain is in use by a mailbox or an app.')); + 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 });