0

In a mongoose schema I'd like to check if a user my save a file. Using everyauth I've got it to work, but it throws an error with the full stacktrace into the console.

SpotSchema.pre('save', function (next) {
   if(!everyauth.user){
        // throws the errror
        next(new Error('Not Logged in'));
        return;
    }
   next();
}

Is there a way to handle this more gracefully?

AyKarsi
  • 9,435
  • 10
  • 54
  • 92

1 Answers1

0

dont throw http://mongoosejs.com/docs/middleware.html

check error handling part and handle the error in your save function