Is there a best practice for cleaning up the errors returned by mongoose? For example, on a save I got the following duplicate key error:
MongoError: E11000 duplicate key error index: dev.users.$username_1 dup key: { : "dweldon" }
I’d like to return something useful to the user but right now I’m parsing error strings in my controllers, which smells like a piping hot cup of wrong.
Don’t parse the string, check the numeric
codeproperty of theMongoErrorobject and present sensible feedback to the user based on the indicated type of error. In your example the code value is11000.