Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update show message method to get custom error messages #42

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class AssetViewerComponent implements OnInit {
constructor(private assetService: AssetService,
private notificationService: NotificationService,
private readonly dialog: MatDialog) {
}
}

private showError(error: string) {
this.notificationService.showError("This asset cannot be deleted");
private showError(error: string, errorMessage: string) {
this.notificationService.showError(errorMessage);
console.error(error);
}

Expand All @@ -51,27 +51,34 @@ export class AssetViewerComponent implements OnInit {
}

onDelete(asset: Asset) {

const dialogData = ConfirmDialogModel.forDelete("asset", `"${asset.name}"`)
const ref = this.dialog.open(ConfirmationDialogComponent, {maxWidth: "20%", data: dialogData});

ref.afterClosed().subscribe(res => {
if (res) {
this.assetService.removeAsset(asset.id).subscribe(() => this.fetch$.next(null),
err => this.showError(err),
() => this.notificationService.showInfo("Successfully deleted")
);

ref.afterClosed().subscribe({
next: res => {
if (res) {
this.assetService.removeAsset(asset.id).subscribe({
next: () => this.fetch$.next(null),
error: err => this.showError(err, "This asset cannot be deleted"),
complete: () => this.notificationService.showInfo("Successfully deleted")
});
}
}
});

}

onCreate() {
const dialogRef = this.dialog.open(AssetEditorDialog);
dialogRef.afterClosed().pipe(first()).subscribe((result: { assetEntryDto?: AssetEntryDto }) => {
const newAsset = result?.assetEntryDto;
if (newAsset) {
this.assetService.createAsset(newAsset).subscribe(() => this.fetch$.next(null), error => this.showError(error), () => this.notificationService.showInfo("Successfully created"));
dialogRef.afterClosed().pipe(first()).subscribe({
next: (result: { assetEntryDto?: AssetEntryDto }) => {
const newAsset = result?.assetEntryDto;
if (newAsset) {
this.assetService.createAsset(newAsset).subscribe({
next: () => this.fetch$.next(null),
error: error => this.showError(error, "This asset cannot be created"),
complete: () => this.notificationService.showInfo("Successfully created")
});
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export class PolicyViewComponent implements OnInit {

this.errorOrUpdateSubscriber = {
next: x => this.fetch$.next(null),
error: err => this.showError(err),
error: err => this.showError(err, "An error occurred."),
complete: () => {
this.notificationService.showInfo("Successfully completed")
},
}

}

ngOnInit(): void {
Expand All @@ -49,14 +49,21 @@ export class PolicyViewComponent implements OnInit {
}

onCreate() {
const dialogRef = this.dialog.open(NewPolicyDialogComponent)
dialogRef.afterClosed().pipe(first()).subscribe((result: PolicyDefinitionResponseDto) => {
if (result) {
this.policyService.createPolicy(result).subscribe(this.errorOrUpdateSubscriber);
const dialogRef = this.dialog.open(NewPolicyDialogComponent);
dialogRef.afterClosed().pipe(first()).subscribe({
next: (result: PolicyDefinitionResponseDto) => {
if (result) {
this.policyService.createPolicy(result).subscribe(
{
next: (response: IdResponseDto) => this.errorOrUpdateSubscriber.next(response),
error: (error: Error) => this.showError(error, "An error occurred while creating the policy.")
}
);
}
}
})
});
}

/**
* simple full-text search - serialize to JSON and see if "searchText"
* is contained
Expand All @@ -71,16 +78,24 @@ export class PolicyViewComponent implements OnInit {
const dialogData = ConfirmDialogModel.forDelete("policy", policyId);

const ref = this.dialog.open(ConfirmationDialogComponent, {maxWidth: '20%', data: dialogData});

ref.afterClosed().subscribe({

ref.afterClosed().subscribe(res => {
if (res) {
this.policyService.deletePolicy(policyId).subscribe(this.errorOrUpdateSubscriber);
next: (res: any) => {
if (res) {
this.policyService.deletePolicy(policyId).subscribe(
{
next: (response: IdResponseDto) => this.errorOrUpdateSubscriber.next(response),
error: (error: Error) => this.showError(error, "An error occurred while deleting the policy.")
}
);
}
}
});
}

private showError(error: Error) {
console.error(error)
this.notificationService.showError('This policy cannot be deleted');
private showError(error: Error, errorMessage: string) {
console.error(error);
this.notificationService.showError(errorMessage);
}
}
Loading