improve the error message on domain removal

This commit is contained in:
Girish Ramakrishnan
2020-02-27 09:48:40 -08:00
parent 82aff74fc2
commit 4ebe143a98
2 changed files with 8 additions and 2 deletions
+7 -1
View File
@@ -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 });