title: Mongoose trying to handle pre-save errors using promises
body: <p>I'm trying to use pre-save to handle user or email exists error and I can't get it to work. If I comment out my pre-save block everything works fine but it returns the default mongoose error in case of duplicate because my schema uses Unique.</p>
  
  <p>I would like to check for username &amp; email unique and send one message containing true or false so that I can handle both at the same time in my frontend. (Btw this is an Express Restful API)</p>
  
  <p>Anyone know how to do it?</p>
  
  <p>Here is my current setup :</p>
  
  <p>My register method called on my post register route when request passes all middlewares etc. ValidateRegisterForm does some validations on the datas and if everything is fine, hashes the password and pass all datas to createUser, else it sends errors.</p>
  
  <pre><code>public register(req, res){
     validateRegisterForm(req.body).then(data =&gt; {
      createUser(data).then(() =&gt; {
        res.send({status: 201});
      }).catch(err =&gt; {
        res.send(err);
      })
    }).catch(err =&gt; {
        res.send(err);
      });
  }
  </code></pre>
  
  <p>My createUser method :</p>
  
  <pre><code>export const createUser = (data) =&gt; {
    return new Promise( async (resolve, reject) =&gt; {
       const userData = JSON.parse(data);
       const newUser = new User(userData);
       await newUser.save()
         .then(() =&gt; resolve())
         .catch(err =&gt; reject(err))
    });
  };
  </code></pre>
  
  <p>And my User schema with the pre-save :</p>
  
  <pre><code>userSchema.pre('save', () =&gt; {
    return new Promise((resolve, reject) =&gt; {
      const userExists =  !! this.findOne('username');
      const emailExists = !! this.findOne('email');
      if (userExists || emailExists){
        const err = JSON.stringify({inUse : {mail: emailExists, usr: userExists}});
        reject(err)
      }
      resolve();
    })
  });
  </code></pre>