diff --git a/src/routes/api/v1/categories.ts b/src/routes/api/v1/categories.ts index 3e6dc42..b6ee1f0 100644 --- a/src/routes/api/v1/categories.ts +++ b/src/routes/api/v1/categories.ts @@ -122,6 +122,10 @@ function post(req: Request, res: Response) { // P2002 -> "Unique constraint failed on the {constraint}" // https://www.prisma.io/docs/reference/api-reference/error-reference res.status(409).json({ status: 'ERROR', errorcode: 'EXISTING', message: 'Category already exists' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); @@ -176,6 +180,10 @@ async function patch(req: Request, res: Response) { // P2002 -> "Unique constraint failed on the {constraint}" // https://www.prisma.io/docs/reference/api-reference/error-reference res.status(409).json({ status: 'ERROR', errorcode: 'EXISTING', message: 'Category already exists' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); diff --git a/src/routes/api/v1/items.ts b/src/routes/api/v1/items.ts index 9b8e99f..c9d2a0d 100644 --- a/src/routes/api/v1/items.ts +++ b/src/routes/api/v1/items.ts @@ -183,6 +183,10 @@ function post(req: Request, res: Response) { // https://www.prisma.io/docs/reference/api-reference/error-reference // FIXME: Is this errormessage right? res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'Item does not exist' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); @@ -255,6 +259,10 @@ async function patch(req: Request, res: Response) { // P2003 -> "Foreign key constraint failed on the field: {field_name}" // https://www.prisma.io/docs/reference/api-reference/error-reference res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'Item does not exist' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); diff --git a/src/routes/api/v1/storageLocations.ts b/src/routes/api/v1/storageLocations.ts index 87c3343..3ff16a2 100644 --- a/src/routes/api/v1/storageLocations.ts +++ b/src/routes/api/v1/storageLocations.ts @@ -113,6 +113,10 @@ function post(req: Request, res: Response) { // https://www.prisma.io/docs/reference/api-reference/error-reference // FIXME: Is this errormessage right? res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageUnitId does not exist' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); @@ -172,6 +176,10 @@ async function patch(req: Request, res: Response) { // https://www.prisma.io/docs/reference/api-reference/error-reference // FIXME: Is this errormessage right? res.status(404).json({ status: 'ERROR', errorcode: 'NOT_EXISTING', message: 'storageUnitId does not exist' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); diff --git a/src/routes/api/v1/storageUnits.ts b/src/routes/api/v1/storageUnits.ts index 8faf547..0de47f9 100644 --- a/src/routes/api/v1/storageUnits.ts +++ b/src/routes/api/v1/storageUnits.ts @@ -122,6 +122,10 @@ function post(req: Request, res: Response) { // P2002 -> "Unique constraint failed on the {constraint}" // https://www.prisma.io/docs/reference/api-reference/error-reference res.status(409).json({ status: 'ERROR', errorcode: 'EXISTING', message: 'storageUnit already exists' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); @@ -157,6 +161,10 @@ function post(req: Request, res: Response) { // P2002 -> "Unique constraint failed on the {constraint}" // https://www.prisma.io/docs/reference/api-reference/error-reference res.status(409).json({ status: 'ERROR', errorcode: 'EXISTING', message: 'storageUnit already exists' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' }); @@ -233,6 +241,10 @@ async function patch(req: Request, res: Response) { // P2002 -> "Unique constraint failed on the {constraint}" // https://www.prisma.io/docs/reference/api-reference/error-reference res.status(409).json({ status: 'ERROR', errorcode: 'EXISTING', message: 'storageUnit already exists' }); + } else if (err.code == 'P2000') { + // P2000 -> "The provided value for the column is too long for the column's type. Column: {column_name}" + // https://www.prisma.io/docs/reference/api-reference/error-reference + res.status(404).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'One or more fields exceed the maximum length restriction' }); } else { log.db.error(err); res.status(500).json({ status: 'ERROR', errorcode: 'DB_ERROR', error: err, message: 'An error occurred during the database operation' });