Skip to content

Commit

Permalink
NAS-132804: Add error handlers (#11233)
Browse files Browse the repository at this point in the history
  • Loading branch information
undsoft authored Dec 25, 2024
1 parent c2af13a commit dacd730
Show file tree
Hide file tree
Showing 29 changed files with 261 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { IxCheckboxComponent } from 'app/modules/forms/ix-forms/components/ix-ch
import { BulkListItemComponent } from 'app/modules/lists/bulk-list-item/bulk-list-item.component';
import { BulkListItem, BulkListItemState } from 'app/modules/lists/bulk-list-item/bulk-list-item.interface';
import { TestDirective } from 'app/modules/test-id/test.directive';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { ApiService } from 'app/services/websocket/api.service';

@UntilDestroy()
Expand Down Expand Up @@ -73,6 +74,7 @@ export class DockerImageDeleteDialogComponent {
private fb: FormBuilder,
private api: ApiService,
private cdr: ChangeDetectorRef,
private errorHandler: ErrorHandlerService,
private dialogRef: MatDialogRef<DockerImageDeleteDialogComponent>,
@Inject(MAT_DIALOG_DATA) public images: ContainerImage[],
) {
Expand All @@ -92,6 +94,7 @@ export class DockerImageDeleteDialogComponent {

this.api.job('core.bulk', ['app.image.delete', deleteParams]).pipe(
filter((job: Job<CoreBulkResponse<void>[], DeleteContainerImageParams[]>) => !!job.result),
this.errorHandler.catchError(),
untilDestroyed(this),
).subscribe((response) => {
response.arguments[1].forEach((params, index: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { FakeProgressBarComponent } from 'app/modules/loader/components/fake-pro
import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service';
import { TestDirective } from 'app/modules/test-id/test.directive';
import { ApplicationsService } from 'app/pages/apps/services/applications.service';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { ApiService } from 'app/services/websocket/api.service';

@UntilDestroy()
Expand Down Expand Up @@ -83,6 +84,7 @@ export class AppBulkUpgradeComponent {
private dialogRef: MatDialogRef<AppBulkUpgradeComponent>,
private appService: ApplicationsService,
private snackbar: SnackbarService,
private errorHandler: ErrorHandlerService,
@Inject(MAT_DIALOG_DATA) private apps: App[],
) {
this.apps = this.apps.filter((app) => app.upgrade_available);
Expand Down Expand Up @@ -152,7 +154,10 @@ export class AppBulkUpgradeComponent {

this.api
.job('core.bulk', ['app.upgrade', payload])
.pipe(untilDestroyed(this))
.pipe(
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe(() => {
this.dialogRef.close();
this.snackbar.success(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class AppInfoCardComponent {
}).afterClosed();
}),
filter(Boolean),
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((options) => this.executeDelete(name, options));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ export class CloudCredentialsCardComponent implements OnInit {
}

getProviders(): void {
this.cloudCredentialService.getProviders().pipe(untilDestroyed(this)).subscribe((providers) => {
providers.forEach((provider) => this.providers.set(provider.name, provider.title));
});
this.cloudCredentialService
.getProviders()
.pipe(
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((providers) => {
providers.forEach((provider) => this.providers.set(provider.name, provider.title));
});
}

setDefaultSort(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { createTable } from 'app/modules/ix-table/utils';
import { TestDirective } from 'app/modules/test-id/test.directive';
import { sshConnectionsCardElements } from 'app/pages/credentials/backup-credentials/ssh-connection-card/ssh-connection-card.elements';
import { SshConnectionFormComponent } from 'app/pages/credentials/backup-credentials/ssh-connection-form/ssh-connection-form.component';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { KeychainCredentialService } from 'app/services/keychain-credential.service';
import { SlideIn } from 'app/services/slide-in';
import { ApiService } from 'app/services/websocket/api.service';
Expand Down Expand Up @@ -93,6 +94,7 @@ export class SshConnectionCardComponent implements OnInit {
private translate: TranslateService,
protected emptyService: EmptyService,
private dialog: DialogService,
private errorHandler: ErrorHandlerService,
private keychainCredentialService: KeychainCredentialService,
) {}

Expand Down Expand Up @@ -139,7 +141,11 @@ export class SshConnectionCardComponent implements OnInit {
})
.pipe(
filter(Boolean),
switchMap(() => this.api.call('keychaincredential.delete', [credential.id])),
switchMap(() => {
return this.api.call('keychaincredential.delete', [credential.id]).pipe(
this.errorHandler.catchError(),
);
}),
untilDestroyed(this),
)
.subscribe(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
SshKeypairFormComponent,
} from 'app/pages/credentials/backup-credentials/ssh-keypair-form/ssh-keypair-form.component';
import { DownloadService } from 'app/services/download.service';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { KeychainCredentialService } from 'app/services/keychain-credential.service';
import { OldSlideInService } from 'app/services/old-slide-in.service';
import { ApiService } from 'app/services/websocket/api.service';
Expand Down Expand Up @@ -103,6 +104,7 @@ export class SshKeypairCardComponent implements OnInit {
private dialog: DialogService,
private keychainCredentialService: KeychainCredentialService,
private download: DownloadService,
private errorHandler: ErrorHandlerService,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -152,7 +154,11 @@ export class SshKeypairCardComponent implements OnInit {
})
.pipe(
filter(Boolean),
switchMap(() => this.api.call('keychaincredential.delete', [credential.id])),
switchMap(() => {
return this.api.call('keychaincredential.delete', [credential.id]).pipe(
this.errorHandler.catchError(),
);
}),
untilDestroyed(this),
)
.subscribe(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { createTable } from 'app/modules/ix-table/utils';
import { TestDirective } from 'app/modules/test-id/test.directive';
import { acmeDnsAuthenticatorListElements } from 'app/pages/credentials/certificates-dash/acme-dns-authenticator-list/acme-dns-authenticator-list.elements';
import { AcmednsFormComponent } from 'app/pages/credentials/certificates-dash/forms/acmedns-form/acmedns-form.component';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { OldSlideInService } from 'app/services/old-slide-in.service';
import { ApiService } from 'app/services/websocket/api.service';

Expand Down Expand Up @@ -97,6 +98,7 @@ export class AcmeDnsAuthenticatorListComponent implements OnInit {
private translate: TranslateService,
protected emptyService: EmptyService,
private dialog: DialogService,
private errorHandler: ErrorHandlerService,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -146,7 +148,11 @@ export class AcmeDnsAuthenticatorListComponent implements OnInit {
})
.pipe(
filter(Boolean),
switchMap(() => this.api.call('acme.dns.authenticator.delete', [authenticator.id])),
switchMap(() => {
return this.api.call('acme.dns.authenticator.delete', [authenticator.id]).pipe(
this.errorHandler.catchError(),
);
}),
untilDestroyed(this),
)
.subscribe(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { OldModalHeaderComponent } from 'app/modules/slide-ins/components/old-mo
import { OldSlideInRef } from 'app/modules/slide-ins/old-slide-in-ref';
import { SLIDE_IN_DATA } from 'app/modules/slide-ins/slide-in.token';
import { TestDirective } from 'app/modules/test-id/test.directive';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { ApiService } from 'app/services/websocket/api.service';

interface DnsAuthenticatorList {
Expand Down Expand Up @@ -101,7 +102,8 @@ export class AcmednsFormComponent implements OnInit {
private translate: TranslateService,
private formBuilder: FormBuilder,
private slideInRef: OldSlideInRef<AcmednsFormComponent>,
private errorHandler: FormErrorHandlerService,
private errorHandler: ErrorHandlerService,
private formErrorHandlerService: FormErrorHandlerService,
private cdr: ChangeDetectorRef,
private api: ApiService,
private changeDetectorRef: ChangeDetectorRef,
Expand All @@ -119,7 +121,10 @@ export class AcmednsFormComponent implements OnInit {
private loadSchemas(): void {
this.isLoading = true;
this.getAuthenticatorSchemas()
.pipe(untilDestroyed(this))
.pipe(
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((schemas: AuthenticatorSchema[]) => {
this.setAuthenticatorOptions(schemas);
this.createAuthenticatorControls(schemas);
Expand Down Expand Up @@ -228,7 +233,7 @@ export class AcmednsFormComponent implements OnInit {
},
error: (error: unknown) => {
this.isLoading = false;
this.errorHandler.handleValidationErrors(error, this.form);
this.formErrorHandlerService.handleValidationErrors(error, this.form);
this.cdr.markForCheck();
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
basicConstraintOptions,
keyUsageOptions,
} from 'app/pages/credentials/certificates-dash/forms/common-steps/certificate-constraints/extensions.constants';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { ApiService } from 'app/services/websocket/api.service';

@UntilDestroy()
Expand Down Expand Up @@ -94,6 +95,7 @@ export class CertificateConstraintsComponent implements OnInit, SummaryProvider
private translate: TranslateService,
private api: ApiService,
private cdr: ChangeDetectorRef,
private errorHandler: ErrorHandlerService,
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -303,6 +305,7 @@ export class CertificateConstraintsComponent implements OnInit, SummaryProvider
this.api.call('certificate.extended_key_usage_choices')
.pipe(
choicesToOptions(),
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((options) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { IxInputComponent } from 'app/modules/forms/ix-forms/components/ix-input
import { IxSelectComponent } from 'app/modules/forms/ix-forms/components/ix-select/ix-select.component';
import { SummaryProvider, SummarySection } from 'app/modules/summary/summary.interface';
import { TestDirective } from 'app/modules/test-id/test.directive';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { SystemGeneralService } from 'app/services/system-general.service';
import { ApiService } from 'app/services/websocket/api.service';

Expand Down Expand Up @@ -76,6 +77,7 @@ export class CertificateOptionsComponent implements OnInit, OnChanges, SummaryPr
private api: ApiService,
private systemGeneralService: SystemGeneralService,
private cdr: ChangeDetectorRef,
private errorHandler: ErrorHandlerService,
) { }

ngOnChanges(): void {
Expand Down Expand Up @@ -147,7 +149,11 @@ export class CertificateOptionsComponent implements OnInit, OnChanges, SummaryPr

private loadSigningAuthorities(): void {
this.systemGeneralService.getUnsignedCas()
.pipe(idNameArrayToOptions(), untilDestroyed(this))
.pipe(
idNameArrayToOptions(),
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((options) => {
if (this.hasSignedBy() && options.length) {
this.form.patchValue({ signedby: options[0].value });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { SnackbarService } from 'app/modules/snackbar/services/snackbar.service'
import { TestDirective } from 'app/modules/test-id/test.directive';
import { groupAdded, groupChanged } from 'app/pages/credentials/groups/store/group.actions';
import { GroupSlice } from 'app/pages/credentials/groups/store/group.selectors';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { UserService } from 'app/services/user.service';
import { ApiService } from 'app/services/websocket/api.service';

Expand Down Expand Up @@ -101,7 +102,8 @@ export class GroupFormComponent implements OnInit {
private api: ApiService,
private slideInRef: OldSlideInRef<GroupFormComponent>,
private cdr: ChangeDetectorRef,
private errorHandler: FormErrorHandlerService,
private errorHandler: ErrorHandlerService,
private formErrorHandler: FormErrorHandlerService,
private translate: TranslateService,
private store$: Store<GroupSlice>,
private snackbar: SnackbarService,
Expand Down Expand Up @@ -198,7 +200,7 @@ export class GroupFormComponent implements OnInit {
},
error: (error: unknown) => {
this.isFormLoading = false;
this.errorHandler.handleValidationErrors(error, this.form);
this.formErrorHandler.handleValidationErrors(error, this.form);
this.cdr.markForCheck();
},
});
Expand Down Expand Up @@ -246,7 +248,11 @@ export class GroupFormComponent implements OnInit {

private getPrivilegesList(): void {
this.api.call('privilege.query', [])
.pipe(untilDestroyed(this)).subscribe((privileges) => {
.pipe(
this.errorHandler.catchError(),
untilDestroyed(this),
)
.subscribe((privileges) => {
this.initialGroupRelatedPrivilegesList = privileges.filter((privilege) => {
return privilege.local_groups.map((group) => group.gid).includes(this.editingGroup?.gid);
});
Expand Down
16 changes: 10 additions & 6 deletions src/app/pages/credentials/users/user-form/user-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { TestDirective } from 'app/modules/test-id/test.directive';
import { userAdded, userChanged } from 'app/pages/credentials/users/store/user.actions';
import { selectUsers } from 'app/pages/credentials/users/store/user.selectors';
import { DownloadService } from 'app/services/download.service';
import { ErrorHandlerService } from 'app/services/error-handler.service';
import { FilesystemService } from 'app/services/filesystem.service';
import { StorageService } from 'app/services/storage.service';
import { UserService } from 'app/services/user.service';
Expand Down Expand Up @@ -218,7 +219,8 @@ export class UserFormComponent implements OnInit {

constructor(
private api: ApiService,
private errorHandler: FormErrorHandlerService,
private errorHandler: ErrorHandlerService,
private formErrorHandler: FormErrorHandlerService,
private cdr: ChangeDetectorRef,
private fb: FormBuilder,
private translate: TranslateService,
Expand Down Expand Up @@ -289,10 +291,12 @@ export class UserFormComponent implements OnInit {
);

if (this.editingUser?.home && this.editingUser.home !== defaultHomePath) {
this.storageService.filesystemStat(this.editingUser.home).pipe(untilDestroyed(this)).subscribe((stat) => {
this.form.patchValue({ home_mode: stat.mode.toString(8).substring(2, 5) });
this.homeModeOldValue = stat.mode.toString(8).substring(2, 5);
});
this.storageService.filesystemStat(this.editingUser.home)
.pipe(this.errorHandler.catchError(), untilDestroyed(this))
.subscribe((stat) => {
this.form.patchValue({ home_mode: stat.mode.toString(8).substring(2, 5) });
this.homeModeOldValue = stat.mode.toString(8).substring(2, 5);
});
} else {
this.form.patchValue({ home_mode: '700' });
this.form.controls.home_mode.disable();
Expand Down Expand Up @@ -395,7 +399,7 @@ export class UserFormComponent implements OnInit {
},
error: (error: unknown) => {
this.isFormLoading = false;
this.errorHandler.handleValidationErrors(error, this.form);
this.formErrorHandler.handleValidationErrors(error, this.form);
this.cdr.markForCheck();
},
});
Expand Down
Loading

0 comments on commit dacd730

Please sign in to comment.