From 0a8612dac8e1c08a118f02a348fd67ac2c425507 Mon Sep 17 00:00:00 2001 From: baalmart Date: Sat, 11 Jan 2025 12:22:02 +0300 Subject: [PATCH] check if the caught error is an instance of HttpError --- src/auth-service/models/User.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/auth-service/models/User.js b/src/auth-service/models/User.js index ba0797063c..66d79d969e 100644 --- a/src/auth-service/models/User.js +++ b/src/auth-service/models/User.js @@ -786,7 +786,10 @@ UserSchema.statics = { } } catch (error) { logger.error(`🐛🐛 Internal Server Error -- ${error.message}`); - next( + if (error instanceof HttpError) { + return next(error); + } + return next( new HttpError( "Internal Server Error", httpStatus.INTERNAL_SERVER_ERROR, @@ -997,7 +1000,10 @@ UserSchema.statics = { } } catch (error) { logger.error(`🐛🐛 Internal Server Error -- ${error.message}`); - next( + if (error instanceof HttpError) { + return next(error); + } + return next( new HttpError( "Internal Server Error", httpStatus.INTERNAL_SERVER_ERROR, @@ -1039,6 +1045,9 @@ UserSchema.statics = { ); } catch (error) { logger.error(`🐛🐛 Internal Server Error -- ${error.message}`); + if (error instanceof HttpError) { + return next(error); + } return next( new HttpError( "Internal Server Error", @@ -1078,7 +1087,10 @@ UserSchema.statics = { } catch (error) { logObject("the models error", error); logger.error(`🐛🐛 Internal Server Error -- ${error.message}`); - next( + if (error instanceof HttpError) { + return next(error); + } + return next( new HttpError( "Internal Server Error", httpStatus.INTERNAL_SERVER_ERROR,