1 files changed, 8 insertions, 0 deletions
diff --git a/src/api/middlewares/errorMiddleware.js b/src/api/middlewares/errorMiddleware.js
index b8de68e..72b6166 100644
--- a/src/api/middlewares/errorMiddleware.js
+++ b/src/api/middlewares/errorMiddleware.js
@@ -1,5 +1,6 @@
import { SafeNSoundError } from '#util/error.js';
import { MongoServerError } from 'mongodb';
+import * as joi from 'joi';
export function handleErrors(err, req, res, _next) {
if (err instanceof MongoServerError) {
@@ -14,6 +15,13 @@ export function handleErrors(err, req, res, _next) {
err = newErr;
}
+ } else if (err instanceof joi.ValidationError) {
+ const newErr = new SafeNSoundError({
+ errCode: 'JOI_VALIDATION_ERROR',
+ message: err.message,
+ validation_details: err.details
+ });
+ err = newErr;
}
if (err instanceof SafeNSoundError) {
|