ER_DUP_ENTRY is passed as code and not in message
This commit is contained in:
@@ -545,7 +545,7 @@ function getDuplicateErrorDetails(errorMessage, locations, portBindings) {
|
|||||||
assert(Array.isArray(locations));
|
assert(Array.isArray(locations));
|
||||||
assert.strictEqual(typeof portBindings, 'object');
|
assert.strictEqual(typeof portBindings, 'object');
|
||||||
|
|
||||||
const match = errorMessage.match(/ER_DUP_ENTRY: Duplicate entry '(.*)' for key '(.*)'/);
|
const match = errorMessage.match(/Duplicate entry '(.*)' for key '(.*)'/);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
debug('Unexpected SQL error message.', errorMessage);
|
debug('Unexpected SQL error message.', errorMessage);
|
||||||
return new BoxError(BoxError.DATABASE_ERROR, errorMessage);
|
return new BoxError(BoxError.DATABASE_ERROR, errorMessage);
|
||||||
|
|||||||
@@ -1065,7 +1065,7 @@ async function setAliases(name, domain, aliases, auditSource) {
|
|||||||
|
|
||||||
const [error] = await safe(database.transaction(queries));
|
const [error] = await safe(database.transaction(queries));
|
||||||
if (error && error.code === 'ER_DUP_ENTRY' && error.message.indexOf('mailboxes_name_domain_unique_index') !== -1) {
|
if (error && error.code === 'ER_DUP_ENTRY' && error.message.indexOf('mailboxes_name_domain_unique_index') !== -1) {
|
||||||
const aliasMatch = error.message.match(new RegExp(`^ER_DUP_ENTRY: Duplicate entry '(.*)-${domain}' for key 'mailboxes_name_domain_unique_index'$`));
|
const aliasMatch = error.message.match(new RegExp(`Duplicate entry '(.*)-${domain}' for key 'mailboxes_name_domain_unique_index'`));
|
||||||
if (!aliasMatch) throw new BoxError(BoxError.ALREADY_EXISTS, error.message);
|
if (!aliasMatch) throw new BoxError(BoxError.ALREADY_EXISTS, error.message);
|
||||||
|
|
||||||
throw new BoxError(BoxError.ALREADY_EXISTS, `Mailbox, mailinglist or alias for ${aliasMatch[1]} already exists`);
|
throw new BoxError(BoxError.ALREADY_EXISTS, `Mailbox, mailinglist or alias for ${aliasMatch[1]} already exists`);
|
||||||
|
|||||||
Reference in New Issue
Block a user