April 2020
Intermediate to advanced
716 pages
18h 55m
English
The validation constraints that are added to the user schema fields will throw error messages if they're violated when user data is saved to the database. To handle these validation errors and other errors that the database may throw when we make queries to it, we will define a helper method that will return a relevant error message that can be propagated in the request-response cycle as appropriate.
We will add the getErrorMessage helper method to the server/helpers/dbErrorHandler.js file. This method will parse and return the error message associated with the specific validation error or other errors that can occur while querying MongoDB using Mongoose.
mern-skeleton/server/helpers/dbErrorHandler.js:
const getErrorMessage ...