rusty1s / mongoose-i18n-error Goto Github PK
View Code? Open in Web Editor NEWlightweight module for node.js/express.js to create beautiful mongoose i18n validation error messages
License: MIT License
lightweight module for node.js/express.js to create beautiful mongoose i18n validation error messages
License: MIT License
i was confused going through the read.me file ; where am I suppose to define this code snippet ?
{
username: {
type: 'required',
message: 'is required',
value: undefined
},
email: {
type: 'regexp',
message: 'is no valid email',
value: 'johndoe.de'
}
}
it would be very helpful if you had a working example. Thanks!
When I insert a duplicated record, Mongo (version 3.4.0) raises this exception:
TypeError: Cannot read property '1' of null\n at parseUniqueError (/app/node_modules/mongoose-i18n-error/index.js:78:17)
In that line of code, mongoose-i18n-error accesses the matches
of the regex that it used in order to recover the field name and its value from the error message sent by mongo.
The message that I receive from Mongo is:
E11000 duplicate key error collection: mydb.users index: phone_1 dup key: { : "+3934000001" }
And the current regex is:
var matches = /index:\s..$(.)_1\sdup key:\s{\s:\s"(.*)"\s}/.exec(err.message);
Maybe this version of mongo sends a different error message from what you were expecting.
This regex solves the problem:
var matches = /index:\s(.)_1\sdup key:\s{\s:\s"(.)"\s}/.exec(err.message);
but I don't know if it's always correct in any version of mongo.
Would you mind to take a look?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.