2

My server returns an empty object if it gets to the last condition, where code is 204:

exports.get_group_profile = function(req, res) {
 Work.findById(req.params.work_id, function(err, work) {
    if (err || !work)
        return res.send(404);
    if (work.admin.id === req.user._id){
        console.log('here');
        return res.json(200, work.profile);
    }
    if (work.users.indexOf(req.user._id)> -1)
        return res.json(201, work.profile);
    if (work.invited.indexOf(req.user._id) > -1)
        return res.json(202, work.profile);
    for (var i=0;i<work.appliers.length;i++) {
        if (work.appliers[i].id == req.user._id)
            return res.json(203, work.profile);
    }
    if (work.visibility!=0){
        console.log(work.profile);
        return res.json(204, work.profile);
    }
    return res.send(404);
});

};

Any condition but this one returns work.profile (which is a virtual in mongoDB) properly. The log before the return prints the object I need but I have no trace of it on my client side. Any idea ?

1 Answer 1

3

From this website: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

This is why you are not seeing anything on the client side.

Sign up to request clarification or add additional context in comments.

2 Comments

You made me realize responses were more meaningful than just a way to talk to my client side! Do you know what is processing this behavior in Express ? And thank you for the link !
I'd guess that, since it's written in some RFC, Express should be ignoring the second argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.