From cd3de258b0dfdc81bb356ebe1554599f35d62014 Mon Sep 17 00:00:00 2001 From: 4gray Date: Sun, 7 Jan 2024 20:48:39 +0100 Subject: [PATCH] feat(portals): add more specific error views --- src/app/services/pwa.service.ts | 12 +++++++- .../stalker-main-container.component.html | 4 +-- .../playlist-error-view.component.html | 6 ++-- .../xtream-main-container.component.html | 9 +++--- .../xtream-main-container.component.scss | 2 ++ .../xtream/xtream-main-container.component.ts | 30 +++++++++++++++++-- src/assets/i18n/en.json | 16 ++++++++-- 7 files changed, 63 insertions(+), 16 deletions(-) diff --git a/src/app/services/pwa.service.ts b/src/app/services/pwa.service.ts index d9bbebf6a..8bb87ee1b 100644 --- a/src/app/services/pwa.service.ts +++ b/src/app/services/pwa.service.ts @@ -4,7 +4,7 @@ import { MatSnackBar } from '@angular/material/snack-bar'; import { SwUpdate } from '@angular/service-worker'; import { Store } from '@ngrx/store'; import { TranslateService } from '@ngx-translate/core'; -import { catchError, throwError } from 'rxjs'; +import { catchError, EMPTY, throwError } from 'rxjs'; import { ERROR, PLAYLIST_PARSE_BY_URL, @@ -172,6 +172,16 @@ export class PwaService extends DataService { }, ...headers, }) + .pipe( + catchError((response) => { + window.postMessage({ + type: ERROR, + status: response.error.status, + message: response.error.message ?? 'Unknown error', + }); + return EMPTY; + }) + ) .subscribe((response) => { window.postMessage({ type: XTREAM_RESPONSE, diff --git a/src/app/stalker/stalker-main-container.component.html b/src/app/stalker/stalker-main-container.component.html index bc0a0aa78..dc5ebcb1b 100644 --- a/src/app/stalker/stalker-main-container.component.html +++ b/src/app/stalker/stalker-main-container.component.html @@ -49,9 +49,9 @@ } @case ('not-available') { } diff --git a/src/app/xtream/playlist-error-view/playlist-error-view.component.html b/src/app/xtream/playlist-error-view/playlist-error-view.component.html index 91ff3a778..0857585b5 100644 --- a/src/app/xtream/playlist-error-view/playlist-error-view.component.html +++ b/src/app/xtream/playlist-error-view/playlist-error-view.component.html @@ -7,15 +7,15 @@
diff --git a/src/app/xtream/xtream-main-container.component.html b/src/app/xtream/xtream-main-container.component.html index a83f8f045..577727dd3 100644 --- a/src/app/xtream/xtream-main-container.component.html +++ b/src/app/xtream/xtream-main-container.component.html @@ -1,6 +1,7 @@ } @else { @switch (currentLayout) { - @case ('expired-account') { + @case ('error-view') { } @case ('category') { diff --git a/src/app/xtream/xtream-main-container.component.scss b/src/app/xtream/xtream-main-container.component.scss index a17abe983..9c3468de1 100644 --- a/src/app/xtream/xtream-main-container.component.scss +++ b/src/app/xtream/xtream-main-container.component.scss @@ -1,6 +1,8 @@ .container { height: calc(100vh - 140px); overflow-y: auto; + display: flex; + justify-content: center; } mat-spinner { diff --git a/src/app/xtream/xtream-main-container.component.ts b/src/app/xtream/xtream-main-container.component.ts index 6539e1c21..92c1668b7 100644 --- a/src/app/xtream/xtream-main-container.component.ts +++ b/src/app/xtream/xtream-main-container.component.ts @@ -88,7 +88,7 @@ type LayoutView = | 'player' | 'serie-details' | 'favorites' - | 'expired-account'; + | 'error-view'; @Component({ selector: 'app-xtream-main-container', @@ -159,6 +159,7 @@ export class XtreamMainContainerComponent implements OnInit { isLoading = true; searchPhrase = this.portalStore.searchPhrase(); contentId: number; + errorViewInfo = { title: '', message: '' }; commandsList = [ new IpcCommand(XTREAM_RESPONSE, (response: XtreamResponse) => @@ -202,8 +203,19 @@ export class XtreamMainContainerComponent implements OnInit { handleResponse(response: XtreamResponse) { if ((response.payload as any)?.user_info?.status === 'Expired') { - this.currentLayout = 'expired-account'; + this.errorViewInfo = { + title: 'PORTALS.ERROR_VIEW.ACCOUNT_EXPIRED.TITLE', + message: 'PORTALS.ERROR_VIEW.ACCOUNT_EXPIRED.DESCRIPTION', + }; + this.currentLayout = 'error-view'; + } else if ((response.payload as any)?.user_info?.auth === 0) { + this.errorViewInfo = { + title: 'PORTALS.ERROR_VIEW.UNAUTHORIZED.TITLE', + message: 'PORTALS.ERROR_VIEW.UNAUTHORIZED.DESCRIPTION', + }; + this.currentLayout = 'error-view'; } + switch (response.action) { case XtreamCodeActions.GetSeriesCategories: case XtreamCodeActions.GetVodCategories: @@ -341,6 +353,20 @@ export class XtreamMainContainerComponent implements OnInit { } showErrorAsNotification(response: { message: string; status: number }) { + if ('status' in response && response.status === 401) { + this.errorViewInfo = { + title: 'PORTALS.ERROR_VIEW.UNAUTHORIZED.TITLE', + message: 'PORTALS.ERROR_VIEW.UNAUTHORIZED.DESCRIPTION', + }; + this.currentLayout = 'error-view'; + } else if ('status' in response && response.status === 404) { + this.errorViewInfo = { + title: 'PORTALS.ERROR_VIEW.NOT_FOUND.TITLE', + message: 'PORTALS.ERROR_VIEW.NOT_FOUND.DESCRIPTION', + }; + this.currentLayout = 'error-view'; + } + this.snackBar.open( `Error: ${response?.message ?? 'Something went wrong'} (Status: ${ response?.status ?? 0 diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 23c33579b..907e258b0 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -235,9 +235,19 @@ "MY_FAVORITES": "My favorites", "ADD_TO_FAVORITES": "Add to favorites", "REMOVE_FROM_FAVORITES": "Remove from favorites", - "ACCOUNT_EXPIRED_VIEW": { - "TITLE": "Account expired", - "DESCRIPTION": "This account has been expired. Please check the credentials in playlist settings or remove it.", + "ERROR_VIEW": { + "ACCOUNT_EXPIRED": { + "TITLE": "Account expired", + "DESCRIPTION": "This account has been expired. Please check the credentials in playlist settings or remove it." + }, + "UNAUTHORIZED": { + "TITLE": "Unauthorized", + "DESCRIPTION": "Please check the credentials in playlist settings or remove it." + }, + "NOT_FOUND": { + "TITLE": "Portal not found", + "DESCRIPTION": "Please check the credentials and portal url in playlist settings or remove it." + }, "PLAYLIST_SETTINGS": "Playlist Settings", "HOME": "Home", "DELETE": "Delete"