I did create my own Observable service that return current tracks of a player.
I'm subscribing to this service on my Angular component this way:
this.playerSubscription = this.player
.player(playlist)
.subscribe(
playerInfo => this.playerInfo = playerInfo,
error => this.router.navigate(['login'], { queryParams: { error: 'expired_token' }})
);
As you can see, when I have an error, I redirect the user to the login page.
The problem is when I do login after a previous error, the subscription returns to me the lastest error sequence and I gonna redirected again to the login page.
On my service, I'm using the BehaviorSubject and doing subject.next(message) to valid sequences, and subject.error(error) to send an error sequence.
How can I forget about the last error after resubscribing to my observable?
Thank you!
UPDATE 1:
I did some new tests here and it only works when I create a new subject every time I subscribe, like bellow:
player(playlist: IPlaylist, fromBegin: boolean): Observable<IPlayerInfo> {
this._player = new BehaviorSubject<IPlayerInfo>({ status: PlayerStatuses.LOADING });
... more code here ...
return this._player.asObservable();
}
Nevermind if it's a Subject or a BehaviorSubject.
Is this a good practice?