以下、ログインの詳細を再度確認してからhttpリクエストを再試行する必要のある401エラーに対して、Angular2の一般的なhttpエラー処理を追加しようとしています。複数のRX観測値を連鎖して1つの関数として返す方法
ログインが完了する前に機能が終了するため、再試行は機能しません。私は、2つ以上のオブザーバブルを連鎖させる方法が必要です。
Typescripts async/awaitを使用してこれを行う方法がわかりますが、これにはRXスタイルの修正が必要ですか?
request(url: string, options?: RequestOptionsArgs, retry: boolean = true): Observable<Response> {
return this.http.request(url, options)
.catch(initialError => {
console.log(initialError);
if (initialError.status === 401) {
// load login screen, and re-auth
let login = new LoginDetails();
login.username = 'John';
login.password = 'John';
// this will call another observable to load a dialog form and get the credentials
this.apiAccountLoginPost(login)
.subscribe(data => {
// save session data
localStorage.setItem('session', data.toJSON());
// retry the http request again
return this.request(url, options); // need to promote this
}, error => {
// process error
return Observable.throw(initialError);
});
// TODO need to return the login retry as a Observable<Response>