From b5255bdd17d83a08bb1d9683131d18e620254e0f Mon Sep 17 00:00:00 2001 From: seb Date: Fri, 25 Sep 2026 11:34:00 +0200 Subject: [PATCH] u --- src/store/article/createUnderParent.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/store/article/createUnderParent.js b/src/store/article/createUnderParent.js index 192aa7a..0dd5640 100644 --- a/src/store/article/createUnderParent.js +++ b/src/store/article/createUnderParent.js @@ -6,6 +6,7 @@ import { CREATE as MSSQL_CREATE_ARTICLETEXT } from '../../providers/mssql/querie import { CREATE as SQLITE_CREATE_ARTICLETEXT } from '../../providers/sqlite3/queries/articletext.js'; import { INSERT as MSSQL_INSERT_HISTORY } from '../../providers/mssql/queries/articlehistory.js'; import { INSERT as SQLITE_INSERT_HISTORY } from '../../providers/sqlite3/queries/articlehistory.js'; +import { isUniqueConstraintError } from '../../providers/provider.js'; import resolveCategoryAccess from '../category/resolveCategoryAccess.js'; import ensureDefaultUnit from '../unit/ensureDefault.js'; import nextSku from '../numbers/nextSku.js'; @@ -50,12 +51,20 @@ export default function createUnderParent(provider) { const sku = await allocateSku(companyId, runner); const slug = slugify(name); - const article = await runner.query(createArticleSql, { - sku, - unitId, - unitamount: 1, - weight: 0, - }); + let article; + try { + article = await runner.query(createArticleSql, { + sku, + unitId, + unitamount: 1, + weight: 0, + }); + } catch (err) { + if (isUniqueConstraintError(err)) { + throw new Error(`SKU "${sku}" already exists`); + } + throw err; + } const id = article.rows[0]?.id ?? article.insertId;