From fcd78fee619d10ec7d78e8c8ec6c3ac4b0a361a1 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 25 Mar 2023 22:47:37 +0000 Subject: [PATCH] fix(sonarr): :bug: Improved the error handling in the sonarr settings page in the UI This should hopefully prevent some odd situations where the settings are in a odd state #4877 --- .../app/settings/sonarr/sonarr.component.ts | 46 ++++++++++++++++--- .../src/app/state/sonarr/sonarr.state.ts | 2 +- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/Ombi/ClientApp/src/app/settings/sonarr/sonarr.component.ts b/src/Ombi/ClientApp/src/app/settings/sonarr/sonarr.component.ts index 573463cf0..3a8a55409 100644 --- a/src/Ombi/ClientApp/src/app/settings/sonarr/sonarr.component.ts +++ b/src/Ombi/ClientApp/src/app/settings/sonarr/sonarr.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from "@angular/core"; -import { UntypedFormBuilder, FormControl, UntypedFormGroup, Validators } from "@angular/forms"; +import { UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms"; import { SonarrFacade } from "app/state/sonarr/sonarr.facade"; -import { finalize, map } from "rxjs"; +import { catchError, finalize, map, of } from "rxjs"; import { ILanguageProfiles, ISonarrProfile, ISonarrRootFolder, ITag } from "../../interfaces"; @@ -95,7 +95,7 @@ export class SonarrComponent implements OnInit { this.tags = []; this.animeTags = []; - if (version.length > 0) { + if (version?.length > 0) { this.sonarrVersion = version[0]; } @@ -132,11 +132,19 @@ export class SonarrComponent implements OnInit { public getProfiles(form: UntypedFormGroup) { this.profilesRunning = true; this.sonarrService.getQualityProfiles(form.value) + .pipe(catchError((_) => { + this.notificationService.error("Could not load Quality Profiles"); + return of([]); + })) .subscribe(x => { + this.profilesRunning = false; + if (x.length === 0) { + return; + } this.qualities = x; this.qualitiesAnime = x; this.qualities.unshift({ name: "Please Select", id: -1 }); - this.profilesRunning = false; + this.notificationService.success("Successfully retrieved the Quality Profiles"); }); } @@ -144,12 +152,19 @@ export class SonarrComponent implements OnInit { public getRootFolders(form: UntypedFormGroup) { this.rootFoldersRunning = true; this.sonarrService.getRootFolders(form.value) + .pipe(catchError((_) => { + this.notificationService.error("Could not load Root Folders"); + return of([]); + })) .subscribe(x => { + this.rootFoldersRunning = false; + if (x.length === 0) { + return; + } this.rootFolders = x; this.rootFolders.unshift({ path: "Please Select", id: -1 }); this.rootFoldersAnime = x; - this.rootFoldersRunning = false; this.notificationService.success("Successfully retrieved the Root Folders"); }); } @@ -157,11 +172,18 @@ export class SonarrComponent implements OnInit { public getLanguageProfiles(form: UntypedFormGroup) { this.langRunning = true; this.sonarrService.getV3LanguageProfiles(form.value) + .pipe(catchError((_) => { + this.notificationService.error("Could not load Language Profiles"); + return of([]); + })) .subscribe(x => { + this.langRunning = false; + if (x.length === 0) { + return; + } this.languageProfiles = x; this.languageProfilesAnime = x; - this.langRunning = false; this.notificationService.success("Successfully retrieved the Language Profiles"); }); } @@ -169,11 +191,18 @@ export class SonarrComponent implements OnInit { public getTags(form: UntypedFormGroup) { this.tagsRunning = true; this.sonarrService.getTags(form.value).pipe( + catchError((_) => { + this.notificationService.error("Could not load Tags"); + return of([]); + }), finalize(() => { this.tagsRunning = false; + if (this.tags.length === 0) { + return; + } this.animeTags.unshift({ label: "None", id: -1 }); this.tags.unshift({ label: "None", id: -1 }); - this.notificationService.success("Successfully retrieved the Tags"); + this.notificationService.success("Successfully retrieved the Tags") }), map(result => { this.tags = result; @@ -204,16 +233,19 @@ export class SonarrComponent implements OnInit { if (form.controls.defaultQualityProfile) { if (form.controls.defaultQualityProfile.value === "-1") { this.notificationService.error("Please check your entered values"); + return; } } if (form.controls.defaultRootPath) { if (form.controls.defaultRootPath.value === "Please Select") { this.notificationService.error("Please check your entered values"); + return; } } if (form.controls.languageProfile) { if (form.controls.languageProfile.value === "Please Select") { this.notificationService.error("Please check your entered values"); + return; } } if (form.controls.animeTag.value == -1) { diff --git a/src/Ombi/ClientApp/src/app/state/sonarr/sonarr.state.ts b/src/Ombi/ClientApp/src/app/state/sonarr/sonarr.state.ts index 4f08896f8..38d2c35e9 100644 --- a/src/Ombi/ClientApp/src/app/state/sonarr/sonarr.state.ts +++ b/src/Ombi/ClientApp/src/app/state/sonarr/sonarr.state.ts @@ -31,7 +31,7 @@ export class SonarrSettingsState { } @Action(UpdateSettings) - public enable(ctx: StateContext, { settings }: UpdateSettings): Observable { + public update(ctx: StateContext, { settings }: UpdateSettings): Observable { const state = ctx.getState(); return this.settingsService.saveSonarr(settings).pipe( tap((_) => ctx.setState({...state, settings})),