This commit is contained in:
seb
2026-09-30 23:11:01 +02:00
parent 120e59631e
commit 956fadcc8d
3 changed files with 35 additions and 4 deletions

View File

@@ -29,6 +29,8 @@ _No content_
| 400 | Invalid id or cannot delete root — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Category not found — `{"error":"…"}` |
| 409 | Category has articles or subcategories — `{"error":"…"}` |
---

View File

@@ -54,7 +54,12 @@ function articleErrorStatus(error) {
if (error.message === 'Unsupported image format' || error.message?.includes('unsupported image format')) return 400;
if (error.message === 'Not authorized') return 403;
if (error.message === 'Parent not found') return 404;
if (error.message === 'Article not found') return 404;
if (
error.message === 'Article not found' ||
error.message?.startsWith('Article not found') ||
error.message?.startsWith('Component article not found') ||
error.message?.startsWith('Option article not found')
) return 404;
if (error.message === 'Image not found') return 404;
if (error.message === 'Name required') return 400;
if (error.message === 'Invalid image order') return 400;
@@ -86,13 +91,17 @@ function articleErrorStatus(error) {
if (error.message === 'Father article not found') return 404;
if (
error.message?.includes('Stückliste') ||
error.message?.includes('options') ||
error.message?.includes('option') ||
error.message?.toLowerCase().includes('option') ||
error.message?.includes('Item at index') ||
error.message?.includes('Option at index') ||
error.message?.includes('Invalid items array') ||
error.message?.includes('Invalid options array') ||
error.message?.includes('Invalid count') ||
error.message?.includes('Invalid sort') ||
error.message?.includes('Invalid mandated') ||
error.message?.includes('circular') ||
error.message?.includes('Circular')
error.message?.includes('Circular') ||
error.message?.includes('Duplicate article')
) return 400;
return 500;
}

View File

@@ -34,6 +34,14 @@ function categoryErrorStatus(error) {
if (error.message === 'Image not found') return 404;
if (error.message === 'Invalid category order') return 400;
if (error.message === 'Invalid parent') return 400;
if (
error.message === 'Category has articles' ||
error.message === 'Category has subcategories' ||
error.message === 'Category is assigned to POS terminals' ||
error.message?.includes('FOREIGN KEY constraint failed') ||
error.message?.includes('foreign key constraint') ||
error.message?.includes('REFERENCE constraint')
) return 409;
return 500;
}
@@ -519,6 +527,18 @@ export function register(app, basePath = '') {
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 404:
* description: Category not found
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 409:
* description: Category has articles or subcategories
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
app.delete(`${basePath}/category/:id`, async (req, res) => {
const parsed = parsePositiveInt(req.params.id, 'id');