我有一个可以包含多个 HTTP 请求的 Angular2 ForkJoin。当 ForkJoin 出错时,我希望能够确定导致错误的 ForkJoin 中请求的 URL 的子域/域。如果错误是 401 Unauthorized,那么我需要尝试重新建立新连接。我需要失败请求的子域/域,以便我可以查找凭据以重新建立令牌,然后再次尝试 ForkJoin 请求。我的 ForkJoin 可能会向不同的域发出多个请求。
return Observable.create(observer =>
{
//JOIN ALL REQUESTS TOGETHER INTO A BATCH TO BE FORKED....
let observableBatch = [];
//ADD OBSERVABLE FOR SINGLE GET REQUEST
if (requestModel.Get)
{
observableBatch.push(this.HttpGet(requestModel.Get));
}
//ADD OBSERVABLE FOR AN ARRAY OF GET REQUESTS
if (requestModel.GetList)
{
for (let item in requestModel.GetList)
{
observableBatch.push(this.HttpGet(requestModel.GetList[ item ]));
}
}
//ADD OBSERVABLE FOR SINGLE POST REQUEST
if (requestModel.Post)
{
observableBatch.push(this.HttpPost(requestModel.Post));
}
//ADD OBSERVABLE FOR AN ARRAY OF POST REQUESTS
if (requestModel.PostList)
{
for (let item in requestModel.PostList)
{
observableBatch.push(this.HttpPost(requestModel.PostList[ item ]));
}
}
/*
FORK JOIN RETURNS AN ARRAY OF RESULT SETS (1 FOR EACH REQUEST IN FORK JOIN)
THIS OBSERVABLE, IF SUCCESSFUL, RETURNS THE FOLLOWING:
[1..N] - THE RAW JSON FROM CMS SERVICE
*/
let forkJoinSubscription = Observable.forkJoin(observableBatch)
.subscribe (
//SUCCESS, WE HAVE JSON RESPONSE(S)
data =>
{
console.log('FORK JOIN SUCCESS !!!', data);
},
//ERROR
err =>
{
console.log('FORK JOIN ERROR...', err);
},
//COMPLETE
() =>
{
if (forkJoinSubscription)
{
forkJoinSubscription.unsubscribe();
}
//console.log('FORK JOIN COMPELETED');
}
);
});
发生错误时,是否可以在 ForkJoin 中的批量 URL 中确定 URL 的子域/域?