Add scouthub-magazzino-be

This commit is contained in:
Lorenzo Sanesi
2026-07-25 11:54:03 +02:00
parent 7f1d0d5ce3
commit 9ceb05cda2
58 changed files with 9711 additions and 0 deletions
@@ -0,0 +1,16 @@
import { Prisma } from '@prisma/client';
import { HttpError } from '../errors';
// Converte gli errori noti di Prisma (vincoli FK, record non trovato) in HttpError
// con uno status code sensato, senza dover ripetere lo stesso catch ovunque.
export function toHttpError(err: unknown, notFoundMessage: string, conflictMessage: string): unknown {
if (err instanceof Prisma.PrismaClientKnownRequestError) {
if (err.code === 'P2025') {
return new HttpError(404, notFoundMessage);
}
if (err.code === 'P2003') {
return new HttpError(409, conflictMessage);
}
}
return err;
}