Skip to content

Commit ec68fac

Browse files
fix: show error notification when server returns error
1 parent ae47f13 commit ec68fac

File tree

10 files changed

+51
-18
lines changed

10 files changed

+51
-18
lines changed

src/app/components/preference/pages/page-advanced-settings/page-advanced-settings.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ export class PageAdvancedSettingsComponent implements OnInit, AfterViewInit, OnD
118118
result.isCopy = isCopy;
119119
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
120120
.toPromise()
121-
.then(() => this.updateData());
122-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
121+
.then(() => {
122+
this.updateData();
123+
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
124+
}, () => {
125+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
126+
})
123127
};
124128
if (item) {
125129
item.type = type;

src/app/components/preference/pages/page-agent-subscriptions/page-agent-subscriptions.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ export class PageAgentSubscriptionsComponent implements OnInit, AfterViewInit, O
123123
result.isCopy = isCopy;
124124
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
125125
.toPromise()
126-
.then(() => this.updateData());
127-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
126+
.then(() => {
127+
this.updateData();
128+
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
129+
}, () => {
130+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
131+
});
128132
};
129133

130134
this.openDialog(DialogAgentsubComponent, item, onOpenDialog, isCopy);

src/app/components/preference/pages/page-alias/page-alias.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ export class PageAliasComponent implements OnInit, OnDestroy, AfterViewInit {
133133
result.isCopy = isCopy;
134134
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
135135
.toPromise()
136-
.then(() => this.updateData());
137-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
136+
.then(() => {
137+
this.updateData();
138+
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
139+
}, () => {
140+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
141+
});
138142
};
139143
if (item) {
140144
item.actionType = type;

src/app/components/preference/pages/page-api-auth/page-api-auth.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export class PageApiAuthComponent implements OnInit, AfterViewInit, OnDestroy {
135135
);
136136
}
137137
this.updateData();
138+
this.alertService.success(`${this.page} Successfully ${(_result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
138139
};
139140

140141
const onOpenDialog = (result) => {
@@ -145,8 +146,9 @@ export class PageApiAuthComponent implements OnInit, AfterViewInit, OnDestroy {
145146
result.isCopy = isCopy;
146147
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
147148
.toPromise()
148-
.then(onServiceRes);
149-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
149+
.then(onServiceRes, () => {
150+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
151+
});
150152
};
151153

152154
this.openDialog(DialogAuthKeyComponent, item, onOpenDialog, isCopy);

src/app/components/preference/pages/page-mapping/page-mapping.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ export class PageMappingComponent implements OnInit, AfterViewInit, OnDestroy {
121121
result.isCopy = isCopy;
122122
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
123123
.toPromise()
124-
.then(() => this.updateData());
124+
.then(() => {
125+
this.updateData();
126+
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
127+
}, () => {
128+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
129+
});
125130
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
126131
};
127132

src/app/components/preference/pages/page-profile/page-profile.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ export class PageProfileComponent implements OnInit {
206206
}
207207
this.alertService.success(`${this.page} Successfully Updated`);
208208

209-
});
209+
}, () => {
210+
this.alertService.error(`Failed to Update ${this.page}`)
211+
});
210212
} else {
211213
this.username.markAsTouched();
212214
this.usergroup.markAsTouched();

src/app/components/preference/pages/page-scripts/page-scripts.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ export class PageScriptsComponent implements OnInit, AfterViewInit, OnDestroy {
123123
result.isCopy = isCopy;
124124
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
125125
.toPromise()
126-
.then(() => this.updateData());
127-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
126+
.then(() => this.updateData(), () => {
127+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
128+
});
128129
};
129130

130131
this.openDialog(DialogScriptsComponent, Functions.cloneObject(item), onOpenDialog, isCopy);

src/app/components/preference/pages/page-system-overview/page-system-overview.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,12 @@ export class PageSystemOverviewComponent implements OnInit, AfterViewInit, OnDes
186186
result.isCopy = isCopy;
187187
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
188188
.toPromise()
189-
.then(() => this.updateData());
190-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
189+
.then(() => {
190+
this.updateData();
191+
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
192+
}, () => {
193+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
194+
});
191195
};
192196

193197
this.openDialog(DialogUsersComponent, item, onOpenDialog, isCopy);

src/app/components/preference/pages/page-user-settings/page-user-settings.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ export class PageUserSettingsComponent implements OnInit, OnDestroy, AfterViewIn
123123
result.isCopy = isCopy;
124124
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
125125
.toPromise()
126-
.then(() => this.updateData());
127-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
126+
.then(() => {
127+
this.updateData();
128+
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
129+
}, () => {
130+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
131+
});
128132
};
129133

130134
if (item) {

src/app/components/preference/pages/page-users/page-users.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ export class PageUsersComponent implements OnInit, OnDestroy, AfterViewInit {
135135
this.authenticationService.logout();
136136
this.router.navigate([{ outlets: { primary: null, system: 'login' } }]);
137137
}
138-
});
139-
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
138+
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
139+
140+
}, () => {
141+
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
142+
});
140143
};
141144

142145
this.openDialog(DialogUsersComponent, Functions.cloneObject(item), onOpenDialog, isCopy);

0 commit comments

Comments
 (0)