0

I need to implement a request that uses multiple independent requests.
I have tried to understand what is the convention for determining the status in the situation where there are different status codes for different requests. (if there is a convention, at the moment it doesn't seem so).

consider these 3 scenarios:

  1. Getting mixed success/failure.
  2. Getting multiple error codes.
  3. Getting multiple success codes.

And this code I just created to simplify things:

    app.get('/1', function (req, res) {
        var postAllThis = [1, 2, 3, 4];
        var successes = [];
        var errors = [];

        postAllThis.forEach(function (number) {
            postThis(number, function (err, returnedObject) {// this is an asynchronous call for each number
                if (err) errors.push(err);
                else successes.push(returnedObject);
                if (errors.length + successes.length === postAllThis.length) {//finished executing all requests
                    var successesAndErrors = successes.concat(errors)
                    if (!allHaveSameCode(successesAndErrors)) // this function checks that not all have the same code
                        res.status(207).send(successesAndErrors)// at the moment set to 207 until further decision
                    else 
                        res.status(statusThatIsSharedByAll(successesAndErrors)).send(successesAndErrors)// assume here that all of them share the same code
                }
            })
        });
    });

I have read about this here and here and several other places, but have yet to find a conclusion.
From what I have read I am thinking about using 207 but I find it hard to justify this in situation 1 (why would the client continue as if the request succeeded), and especially in situation 2 (only errors - why use a success code).
Besides that the documentation of WebDav 207 status here says that the response body should be xml, but I want the response to be sent as an array, so I am a little confused about why it has to be xml.

Community
  • 1
  • 1
Achi Even-dar
  • 427
  • 1
  • 10
  • 20

0 Answers0