forked from meanjs/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
853 additions
and
706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Get unique error field name | ||
*/ | ||
var getUniqueErrorMessage = function(err) { | ||
var output; | ||
|
||
try { | ||
var fieldName = err.err.substring(err.err.lastIndexOf('.$') + 2, err.err.lastIndexOf('_1')); | ||
output = fieldName.charAt(0).toUpperCase() + fieldName.slice(1) + ' already exist'; | ||
|
||
} catch(ex) { | ||
output = 'Unique field already exist'; | ||
} | ||
|
||
return output; | ||
}; | ||
|
||
/** | ||
* Get the error message from error object | ||
*/ | ||
exports.getErrorMessage = function(err) { | ||
var message = ''; | ||
|
||
if (err.code) { | ||
switch (err.code) { | ||
case 11000: | ||
case 11001: | ||
message = getUniqueErrorMessage(err); | ||
break; | ||
default: | ||
message = 'Something went wrong'; | ||
} | ||
} else { | ||
for (var errName in err.errors) { | ||
if (err.errors[errName].message) message = err.errors[errName].message; | ||
} | ||
} | ||
|
||
return message; | ||
}; |
Oops, something went wrong.