Files
meanTorrent/app/controllers/errors.server.controller.js
Max 867cf5e329 Fix typo in Error handling controller code
On the frontend, the error message 'Username already exist' appears when creating a user with the same username as an existing user.  Grammatically, this error looks strange.  A more proper error message would be 'Username already exists'.  Possibly later on support can be added to properly conjugate this error message for a 'plural' field.
2014-08-06 19:28:24 -06:00

43 lines
822 B
JavaScript

'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 exists';
} catch(ex) {
output = 'Unique field already exists';
}
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;
};