diff --git a/projects/gameboard-ui/src/app/api/toc.service.ts b/projects/gameboard-ui/src/app/api/toc.service.ts index b75ecf76..2281f3b2 100644 --- a/projects/gameboard-ui/src/app/api/toc.service.ts +++ b/projects/gameboard-ui/src/app/api/toc.service.ts @@ -3,13 +3,12 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { Observable, of, BehaviorSubject, iif, Subject } from 'rxjs'; -import { switchMap, map, tap, delay } from 'rxjs/operators'; +import { Observable, of, BehaviorSubject } from 'rxjs'; +import { switchMap, map, tap, delay, catchError } from 'rxjs/operators'; import { ConfigService } from '../utility/config.service'; +import { LogService } from '../services/log.service'; -@Injectable({ - providedIn: 'root' -}) +@Injectable({ providedIn: 'root' }) export class TocService { toc$: Observable; tocfile$: (id: string) => Observable; @@ -17,8 +16,9 @@ export class TocService { private cache: TocFile[] = []; constructor( + config: ConfigService, private http: HttpClient, - private config: ConfigService + private log: LogService ) { const tag = `?t=${new Date().valueOf()}`; const tocUrl = `${config.tochost}/${config.settings.tocfile + ''}${tag}`; @@ -30,32 +30,47 @@ export class TocService { url += `/${config.settings.tocfile?.substring(0, i)}`; } - this.toc$ = iif( - () => !!config.settings.tocfile, - http.get(tocUrl).pipe( + if (!!config.settings.tocfile) { + this.toc$ = http.get(tocUrl).pipe( + catchError(err => { + // don't report error here - ops will know what the 404 means + this.cache = []; + return []; + }), switchMap((list) => this.mapTocFromList(list)), tap(list => this.cache = list), - ), - of([]) - ).pipe( - tap(() => this.loaded$.next(true)) - ); + ); + } + else { + this.log.logInfo("No toc file configured. Skipped loading."); + this.toc$ = of([]); + } + + this.toc$ = this.toc$.pipe(tap(toc => this.loaded$.next(true))); this.tocfile$ = (id: string) => { const tocfile = this.cache.find(f => f.filename === id || f.link === id ); + if (!tocfile) { return of('not found'); } + if (!!tocfile.text) { return of(tocfile.text); } + + const tocFileUrl = `${url}/${tocfile?.filename}${tag}`; return this.http.get( - `${url}/${tocfile?.filename}${tag}`, - { responseType: 'text'} + tocFileUrl, + { responseType: 'text' } ).pipe( + catchError(err => { + // don't report - ops will know 404 + return ''; + }), tap(t => tocfile.text = t) ); }; diff --git a/projects/gameboard-ui/src/app/app.component.html b/projects/gameboard-ui/src/app/app.component.html index c2611f9a..4e009137 100644 --- a/projects/gameboard-ui/src/app/app.component.html +++ b/projects/gameboard-ui/src/app/app.component.html @@ -5,16 +5,15 @@