File tree Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ const parseError = (err) => {
3535 TokenExpiredError : { message : 'JWT::Expired' , statusCode : 401 } ,
3636 MongoServerError : ( code ) => {
3737 if ( code === 11000 ) return { message : 'Database::Duplicated::Fields' , statusCode : 400 } ;
38- return { message : 'Database:Error' , statusCode : 500 } ;
38+ return { message : err . message , statusCode : err . statusCode } ;
3939 }
4040 } ;
4141 const handler = errorMap [ err . name ] || errorMap . MongoServerError ;
@@ -54,7 +54,6 @@ const parseError = (err) => {
5454const errorHandler = ( err , req , res , next ) => {
5555 err . statusCode = err . statusCode || 500 ;
5656 err . message = err . message || 'Server Error' ;
57- console . log ( '[Quantum Cloud] @globalErrorHandler:' , err ) ;
5857 if ( err instanceof RuntimeError ) {
5958 return res . status ( err . statusCode ) . send ( { status : 'error' , message : err . message } ) ;
6059 }
Original file line number Diff line number Diff line change @@ -107,9 +107,12 @@ UserSchema.pre('findOneAndDelete', async function(){
107107 } ) ;
108108} ) ;
109109
110- // DOCKER CONTAINER IS CREATED IF ERROR EXISTS
111110UserSchema . pre ( 'save' , async function ( next ) {
112111 try {
112+ if ( ! this . isModified ( 'password' ) ) return next ( ) ;
113+ this . username = this . username . replace ( / \s / g, '' ) ;
114+ this . password = await bcrypt . hash ( this . password , 12 ) ;
115+ this . passwordConfirm = undefined ;
113116 // The existence of "global.logStreamStore" is checked
114117 // because it is an object that is created when the server runs.
115118 // However, when you run the CLI and choose the "Create new user"
@@ -127,11 +130,6 @@ UserSchema.pre('save', async function(next){
127130 console . log ( `[Quantum Cloud] CRITICAL ERROR (at @models/user - pre save middleware): ${ error } ` )
128131 } ) ;
129132 }
130- if ( ! this . isModified ( 'password' ) ) return next ( ) ;
131- this . username = this . username . replace ( / \s / g, '' ) ;
132- this . password = await bcrypt . hash ( this . password , 12 ) ;
133- this . passwordConfirm = undefined ;
134-
135133 if ( ! this . isModified ( 'password' ) || this . isNew ) return next ( ) ;
136134 this . passwordChangedAt = Date . now ( ) - 1000 ;
137135 next ( ) ;
You can’t perform that action at this time.
0 commit comments