I am building an angularJS based application and I am running passportjs on my nodeJS back-end. Authentication works but error handling is not a precise as I want it to be. For example when I am querying my mongoDB and something fails I do the following:
Node:
response.send(406, {error: "Email already in use"});
Angular:
settingsService.saveUserOnServer($scope.settings).then(
function (user) {
//Success
},
function (response) {
console.log(response);
var error = response.data.error;
$cordovaToast.show(error, 'short', 'bottom');
});
This will toast "Email already in use". I want to have the same functionality when using passportjs:
// if no user is found, return the message
if (!user)
return done(null, false, {message: 'No user found'});
This is the response I get in angular:
Object {data: "Unauthorized", status: 401, headers: function, config: Object, statusText: "Unauthorized"}
How can I retrieve the 'No user found' message? Thanks in advance!