Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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
                     });
                 });

    });
  1. middlewares.requireLogin(token verify process) is working fine.
  2. I solved that error by using this line res.status(200).send().In that process in client its showing success code is 400.

  3. so how can i solve that one. i want to get the data and status code as 200

share|improve this question
up vote 1 down vote accepted

You are calling res.send() or res.end() twice somewhere in your code. Kindly check with the middleware, or other places with the response object if it calls a function that sends out an HTTP response BEFORE your last res.send() that you intended.

share|improve this answer
    
thanq @jekk for the rply, no i did not repeated that line in any where of that particular service and middlewares. – Simha Chalam 19 hours ago
    
ya ,thanq @jekk, i repeated two times next() in middle ware – Simha Chalam 19 hours ago
    
Glad to have helped @SimhaChalam – Jekk 17 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.