From 49a6f28200cc24079d75f84224666bbc9dd839b1 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Mon, 13 Jan 2025 16:32:13 -0700 Subject: [PATCH] handle error closure events properly --- .../ui/src/app/pages/init/init.service.ts | 10 ++++++- .../sideload/sideload.service.ts | 27 +++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/web/projects/ui/src/app/pages/init/init.service.ts b/web/projects/ui/src/app/pages/init/init.service.ts index ae0156dc5..9fbcc933d 100644 --- a/web/projects/ui/src/app/pages/init/init.service.ts +++ b/web/projects/ui/src/app/pages/init/init.service.ts @@ -26,7 +26,15 @@ export class InitService extends Observable { from(this.api.initGetProgress()), ).pipe( switchMap(({ guid, progress }) => - this.api.openWebsocket$(guid).pipe(startWith(progress)), + this.api + .openWebsocket$(guid, { + closeObserver: { + next: () => { + this.state.syncState() + }, + }, + }) + .pipe(startWith(progress)), ), map(({ phases, overall }) => ({ total: getOverallDecimal(overall), diff --git a/web/projects/ui/src/app/pages/server-routes/sideload/sideload.service.ts b/web/projects/ui/src/app/pages/server-routes/sideload/sideload.service.ts index e53f453f3..df6ec0868 100644 --- a/web/projects/ui/src/app/pages/server-routes/sideload/sideload.service.ts +++ b/web/projects/ui/src/app/pages/server-routes/sideload/sideload.service.ts @@ -23,16 +23,27 @@ export class SideloadService { readonly progress$ = this.guid$.pipe( switchMap(guid => - this.api.openWebsocket$(guid).pipe( - tap(p => { - if (p.overall === true) { - this.router.navigate([''], { replaceUrl: true }) - } - }), - ), + this.api + .openWebsocket$(guid, { + closeObserver: { + next: event => { + if (event.code !== 1000) { + this.errorService.handleError(event.reason) + } + }, + }, + }) + .pipe( + tap(p => { + if (p.overall === true) { + this.router.navigate([''], { replaceUrl: true }) + } + }), + endWith(null), + ), ), catchError(e => { - this.errorService.handleError(e) + this.errorService.handleError('Websocket connection broken. Try again.') return EMPTY }), shareReplay(1),