code -> sqlCode

This commit is contained in:
Girish Ramakrishnan
2025-09-29 11:55:15 +02:00
parent 906e3f8cea
commit 5dd5a20fc1
14 changed files with 36 additions and 37 deletions
+3 -2
View File
@@ -178,7 +178,7 @@ async function add(domain, data, auditSource) {
];
[error] = await safe(database.transaction(queries));
if (error && error.code === 'ER_DUP_ENTRY') throw new BoxError(BoxError.ALREADY_EXISTS, 'Domain already exists');
if (error && error.sqlCode === 'ER_DUP_ENTRY') throw new BoxError(BoxError.ALREADY_EXISTS, 'Domain already exists');
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error);
await reverseProxy.setFallbackCertificate(domain, fallbackCertificate);
@@ -298,7 +298,8 @@ async function del(domain, auditSource) {
];
const [error, results] = await safe(database.transaction(queries));
if (error && error.code === 'ER_ROW_IS_REFERENCED_2') {
console.dir(error);
if (error && error.sqlCode === 'ER_ROW_IS_REFERENCED_2') {
if (error.message.includes('mailboxes_aliasDomain_constraint')) throw new BoxError(BoxError.CONFLICT, 'Domain is in use in a mailbox, list or an alias');
if (error.message.includes('mailboxes_domain_constraint')) throw new BoxError(BoxError.CONFLICT, 'Domain is in use in a mailbox, list or an alias');
if (error.message.includes('apps_mailDomain_constraint')) throw new BoxError(BoxError.CONFLICT, 'Domain is in use in an app\'s mailbox section');