If an observable inside a route resolver fails, the Angular router does not navigate to the route. I want to get around this by wrapping my call in another observable, which always successfully returns, like so:
private fetchUserDataOrReturnNullIfError(url: string, httpOptions: any): Observable<any> { const getLoggedInUserDataOrNullIfCallFails: Observable<any> = new Observable(observer => { this.httpClient.get(url, httpOptions).subscribe(userData => { console.log('Got user data: ', userData); observer.next(userData); }, err => { console.log('Call failed'); observer.next('lol'); }); }); return getLoggedInUserDataOrNullIfCallFails; } My resolve looks like this:
resolve(): Observable<any> { //stuff and things return this.fetchUserDataOrReturnNullIfError(url, httpOptions); } My understanding was that the inner observable would error, and the outer observable would successfully call next, thereby the route would successfully resolve. This isn't happening.
What am I doing wrong / how do I solve this?
My goal is for the resolve to return the result of the call, if successful, and to return lol if failing, but to always go to the next route.