summary refs log tree commit diff
path: root/src/api/middlewares/errorMiddleware.js
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-02 12:16:30 +0200
committerRory& <root@rory.gay>2025-06-02 12:16:30 +0200
commitea65ae3a11e03fa66f809be89f86baabf627ad82 (patch)
tree377af52ba925269feea603ab716fd52d950154bb /src/api/middlewares/errorMiddleware.js
parentFix readme (diff)
downloadnodejs-final-assignment-ea65ae3a11e03fa66f809be89f86baabf627ad82.tar.xz
Try to fix auth
Diffstat (limited to 'src/api/middlewares/errorMiddleware.js')
-rw-r--r--src/api/middlewares/errorMiddleware.js8
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) {