2017-11-13 2 views
0

アムをキャンセル余分な要求を送信しています。コードは動作しますが、devToolsネットワークのタップで、最後に余分な要求が送信され、キャンセルされていることに気付きました。私はここで間違ってやっていることは、コードです:ここでは角度のHttpClient要求は試行回数との間の遅延で要求を作るために<em>Angulars</em><em>のHttpClient</em>サービスを利用しようとしていること

return this.http.post<LoginSuccessPayload>('/api/auth/signin', payload).pipe(
    retryWhen(errors => { 
    return errors.pipe(
     mergeMap((er: any) => { 
     if (er.status === 504 || er.status === 503) { 
      return of(er.status).pipe(delay(1000)); 
     } 
     return _throw({message: er.error.message || 'Notification.Core.loginError'}); 
     }), 
     take(3), 
     concat(_throw({message: 'Notification.Core.networkError'})) 
    ); 
    }) 
); 

Firefoxのクロームネットワーク]タブの画像であり、そこに3つの要求することが、そのは4を作り、最後の1 enter image description here

をキャンセルする必要があります
+0

どのようなネットワークコールが表示されますか? – martin

答えて

0

私はそれをどのように解決したのですか?リクエストごとに2回目の遅延があり、余分なキャンセル要求はありません。3回の試行があります。

return this.http.post<LoginSuccessPayload>('/api/auth/signin', payload).pipe(
    retryWhen(errors => errors.pipe(
    switchMap((error) => { 
     if (error.status === 504 || error.status === 503) { 
     return of(error.status); 
     } 
     return _throw({message: error.error.message || 'Notification.Core.loginError'}); 
    }), 
    scan((acc) => { 
     return acc + 1; 
    }, 0), 
    takeWhile(acc => acc < 3), 
    delay(1000), 
    concat(_throw({message: 'Notification.Core.networkError'})) 
)) 
); 
関連する問題