Error is:
Possibly unhandled Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
at ServerResponse.res.set.res.header
1.all nodejs services working fine before set the token in header.
2.after set the token in header in angularjs creating that error in nodejs server.
my angularjs code is :
menu.factory('allServs', function ($q, $http,$cookieStore) {
propDetails:function (property_id) {
var req = {
method: 'GET',
url: '/v1/xxxxxxx/'+xxxxxxx
}
if($cookieStore.get('userDetails')){
req.headers = {
"authorization": $cookieStore.get('userDetails').token
}
}
var deferred = $q.defer(),
httpPromise = $http(req);
httpPromise.then(function (response) {
alert("response"+JSON.stringify(response));
deferred.resolve(response);
}, function (error) {
alert("error"+JSON.stringify(error));
console.error(error);
});
return deferred.promise;
}
}
3.In nodejs ,webservice token is getting ,decoding is fine and getting the response details but the problem is last line at the time of return json data.
app.get('/v1/xxxxxxx/:xxxxx',middlewares.requireLogin,function(req, res) {
core.property.getProjectGroup(options, function (result) {
return res.send({
result:result
});
});
});
- middlewares.requireLogin(token verify process) is working fine.
I solved that error by using this line res.status(200).send().In that process in client its showing success code is 400.
so how can i solve that one. i want to get the data and status code as 200