Skip to content
Advertisement

UnhandledPromiseRejectionWarning: ValidationError

I’m running into a trouble since a few days. I’m learning the MEAN stack, but during creation of a user on mongo using mongoose schema, I have this problem :

(node:93337) UnhandledPromiseRejectionWarning: ValidationError: User validation failed: username: Path username is required., password: Path password is required., email: Path email is required.

Here’s my code :

The server part :

JavaScript

JavaScript

The UserSchema :

JavaScript

Here are the add-ons I’m using :

  • Express,
  • Nodemon,
  • Morgan,
  • Body Parser,
  • Mongo (With mongod running & Mongoose)

Advertisement

Answer

Okay I found the problem…

Clearly, the problem is due to one of these two :

  • The browser used,
  • The extension sending the POST request

Surprise, I tried with Postman, and the request successfully work. So all the code was great, the problem came from one of the two up.

So, that learned me a thing. If it’s not your code, It’s the software you’re using that can destroy all you have done

Advertisement