我需要实现一个使用多个独立请求的请求 我试图了解在不同请求的状态代码有不同的情况下确定状态的惯例是什么。 (如果有约定,目前似乎不是这样)。
考虑以下三种情况:
我刚刚创建的代码是为了简化:
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
}
})
});
});
我已阅读过此here和here以及其他几个地方,但尚未得出结论。
根据我的阅读,我正在考虑使用207,但我发现在情况1中很难证明这一点(为什么客户端会像请求成功一样继续),特别是在情境2中(只有错误 - 为什么要使用成功代码) 。
除此之外,WebDav 207状态here的文档说响应体应该是xml,但我希望响应作为数组发送,所以我对它为什么必须是xml感到有点困惑。