Skip to content

Commit c7668d4

Browse files
authored
Merge pull request #264 from ioet/254-display-error-messages-from-backend
closes #254
2 parents 3c7e789 + 7c817ab commit c7668d4

File tree

6 files changed

+61
-30
lines changed

6 files changed

+61
-30
lines changed

src/app/modules/activities-management/store/activity-management.effects.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class ActivityEffects {
1616
private actions$: Actions,
1717
private activityService: ActivityService,
1818
private toastrService: ToastrService
19-
) {}
19+
) { }
2020

2121
@Effect()
2222
getActivities$: Observable<Action> = this.actions$.pipe(
@@ -26,7 +26,10 @@ export class ActivityEffects {
2626
map((activities: Activity[]) => {
2727
return new actions.LoadActivitiesSuccess(activities);
2828
}),
29-
catchError((error) => of(new actions.LoadActivitiesFail(error)))
29+
catchError((error) => {
30+
this.toastrService.error(error.error.message);
31+
return of(new actions.LoadActivitiesFail(error));
32+
})
3033
)
3134
)
3235
);
@@ -42,7 +45,7 @@ export class ActivityEffects {
4245
return new actions.CreateActivitySuccess(activityData);
4346
}),
4447
catchError((error) => {
45-
this.toastrService.error(UNEXPECTED_ERROR);
48+
this.toastrService.error(error.error.message);
4649
return of(new actions.CreateActivityFail(error));
4750
})
4851
)
@@ -60,7 +63,7 @@ export class ActivityEffects {
6063
return new actions.DeleteActivitySuccess(activityId);
6164
}),
6265
catchError((error) => {
63-
this.toastrService.error(UNEXPECTED_ERROR);
66+
this.toastrService.error(error.error.message);
6467
return of(new actions.DeleteActivityFail(error));
6568
})
6669
)
@@ -78,7 +81,7 @@ export class ActivityEffects {
7881
return new actions.UpdateActivitySuccess(activityData);
7982
}),
8083
catchError((error) => {
81-
this.toastrService.error(UNEXPECTED_ERROR);
84+
this.toastrService.error(error.error.message);
8285
return of(new actions.UpdateActivityFail(error));
8386
})
8487
)

src/app/modules/customer-management/components/projects-type/store/project-type.effects.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class ProjectTypeEffects {
1616
private actions$: Actions,
1717
private projectTypeService: ProjectTypeService,
1818
private toastrService: ToastrService
19-
) {}
19+
) { }
2020

2121
@Effect()
2222
getProjectTypes$: Observable<Action> = this.actions$.pipe(
@@ -26,7 +26,10 @@ export class ProjectTypeEffects {
2626
map((projectTypes: ProjectType[]) => {
2727
return new actions.LoadProjectTypesSuccess(projectTypes);
2828
}),
29-
catchError((error) => of(new actions.LoadProjectTypesFail(error)))
29+
catchError((error) => {
30+
this.toastrService.error(error.error.message);
31+
return of(new actions.LoadProjectTypesFail(error));
32+
})
3033
)
3134
)
3235
);
@@ -42,7 +45,7 @@ export class ProjectTypeEffects {
4245
return new actions.CreateProjectTypeSuccess(projectTypeData);
4346
}),
4447
catchError((error) => {
45-
this.toastrService.error(UNEXPECTED_ERROR);
48+
this.toastrService.error(error.error.message);
4649
return of(new actions.CreateProjectTypeFail(error));
4750
})
4851
)
@@ -60,7 +63,7 @@ export class ProjectTypeEffects {
6063
return new actions.DeleteProjectTypeSuccess(protectTypeId);
6164
}),
6265
catchError((error) => {
63-
this.toastrService.error(UNEXPECTED_ERROR);
66+
this.toastrService.error(error.error.message);
6467
return of(new actions.DeleteProjectTypeFail(error));
6568
})
6669
)
@@ -78,7 +81,7 @@ export class ProjectTypeEffects {
7881
return new actions.UpdateProjectTypeSuccess(projectTypeData);
7982
}),
8083
catchError((error) => {
81-
this.toastrService.error(UNEXPECTED_ERROR);
84+
this.toastrService.error(error.error.message);
8285
return of(new actions.UpdateProjectTypeFail(error));
8386
})
8487
)

src/app/modules/customer-management/components/projects/components/store/project.effects.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ProjectEffects {
1414
private actions$: Actions,
1515
private projectService: ProjectService,
1616
private toastrService: ToastrService
17-
) {}
17+
) { }
1818

1919
@Effect()
2020
loadProjects$: Observable<Action> = this.actions$.pipe(
@@ -25,6 +25,7 @@ export class ProjectEffects {
2525
return new actions.LoadProjectsSuccess(projects);
2626
}),
2727
catchError((error) => {
28+
this.toastrService.error(error.error.message);
2829
return of(new actions.LoadProjectsFail(error));
2930
})
3031
)
@@ -39,7 +40,10 @@ export class ProjectEffects {
3940
map((project) => {
4041
return new actions.LoadCustomerProjectsSuccess(project);
4142
}),
42-
catchError((error) => of(new actions.LoadCustomerProjectsFail(error)))
43+
catchError((error) => {
44+
this.toastrService.error(error.error.message);
45+
return of(new actions.LoadCustomerProjectsFail(error));
46+
})
4347
)
4448
)
4549
);
@@ -55,7 +59,7 @@ export class ProjectEffects {
5559
return new actions.CreateProjectSuccess(projectData);
5660
}),
5761
catchError((error) => {
58-
this.toastrService.error(UNEXPECTED_ERROR);
62+
this.toastrService.error(error.error.message);
5963
return of(new actions.CreateProjectFail(error));
6064
})
6165
)
@@ -73,7 +77,7 @@ export class ProjectEffects {
7377
return new actions.UpdateProjectSuccess(projectData);
7478
}),
7579
catchError((error) => {
76-
this.toastrService.error(UNEXPECTED_ERROR);
80+
this.toastrService.error(error.error.message);
7781
return of(new actions.UpdateProjectFail(error));
7882
})
7983
)
@@ -91,7 +95,7 @@ export class ProjectEffects {
9195
return new actions.DeleteProjectSuccess(projectId);
9296
}),
9397
catchError((error) => {
94-
this.toastrService.error(UNEXPECTED_ERROR);
98+
this.toastrService.error(error.error.message);
9599
return of(new actions.DeleteProjectFail(error));
96100
})
97101
)

src/app/modules/customer-management/store/customer-management.effects.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class CustomerEffects {
1515
private actions$: Actions,
1616
private customerService: CustomerService,
1717
private toastrService: ToastrService
18-
) {}
18+
) { }
1919

2020
@Effect()
2121
loadCustomers$: Observable<Action> = this.actions$.pipe(
@@ -25,7 +25,11 @@ export class CustomerEffects {
2525
map((customers) => {
2626
return new actions.LoadCustomersSuccess(customers);
2727
}),
28-
catchError((error) => of(new actions.LoadCustomersFail(error)))
28+
catchError((error) => {
29+
this.toastrService.error(error.error.message);
30+
return of(new actions.LoadCustomersFail(error));
31+
}
32+
)
2933
)
3034
)
3135
);
@@ -41,7 +45,7 @@ export class CustomerEffects {
4145
return new actions.CreateCustomerSuccess(customerData);
4246
}),
4347
catchError((error) => {
44-
this.toastrService.error(UNEXPECTED_ERROR);
48+
this.toastrService.error(error.error.message);
4549
return of(new actions.CreateCustomerFail(error));
4650
})
4751
)
@@ -59,7 +63,7 @@ export class CustomerEffects {
5963
return new actions.DeleteCustomerSuccesss(customerId);
6064
}),
6165
catchError((error) => {
62-
this.toastrService.error(UNEXPECTED_ERROR);
66+
this.toastrService.error(error.error.message);
6367
return of(new actions.DeleteCustomerFail(error));
6468
})
6569
)
@@ -77,7 +81,7 @@ export class CustomerEffects {
7781
return new actions.UpdateCustomerSuccess(customerData);
7882
}),
7983
catchError((error) => {
80-
this.toastrService.error(UNEXPECTED_ERROR);
84+
this.toastrService.error(error.error.message);
8185
return of(new actions.UpdateCustomerFail(error));
8286
})
8387
)

src/app/modules/shared/store/technology.effects.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ToastrService } from 'ngx-toastr';
12
import { Injectable } from '@angular/core';
23
import { ofType, Actions, Effect } from '@ngrx/effects';
34
import { Action } from '@ngrx/store';
@@ -8,7 +9,8 @@ import * as actions from './technology.actions';
89

910
@Injectable()
1011
export class TechnologyEffects {
11-
constructor(private actions$: Actions, private technologyService: TechnologyService) {}
12+
13+
constructor(private toastrService: ToastrService, private actions$: Actions, private technologyService: TechnologyService) { }
1214

1315
@Effect()
1416
findTechnology$: Observable<Action> = this.actions$.pipe(
@@ -19,7 +21,10 @@ export class TechnologyEffects {
1921
map((technology) => {
2022
return new actions.FindTechnologySuccess(technology);
2123
}),
22-
catchError((error) => of(new actions.FindTechnologyFail(error)))
24+
catchError((error) => {
25+
this.toastrService.error(error.error.message);
26+
return of(new actions.FindTechnologyFail(error));
27+
})
2328
)
2429
)
2530
);

src/app/modules/time-clock/store/entry.effects.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as actions from './entry.actions';
1010

1111
@Injectable()
1212
export class EntryEffects {
13-
constructor(private actions$: Actions, private entryService: EntryService, private toastrService: ToastrService) {}
13+
constructor(private actions$: Actions, private entryService: EntryService, private toastrService: ToastrService) { }
1414

1515
@Effect()
1616
loadEntriesSummary$: Observable<Action> = this.actions$.pipe(
@@ -20,7 +20,10 @@ export class EntryEffects {
2020
map((response) => {
2121
return new actions.LoadEntriesSummarySuccess(response);
2222
}),
23-
catchError((error) => of(new actions.LoadEntriesSummaryFail()))
23+
catchError((error) => {
24+
this.toastrService.success(error);
25+
return of(new actions.LoadEntriesSummaryFail());
26+
})
2427
)
2528
)
2629
);
@@ -33,7 +36,10 @@ export class EntryEffects {
3336
map((activeEntry) => {
3437
return new actions.LoadActiveEntrySuccess(activeEntry);
3538
}),
36-
catchError((error) => of(new actions.LoadActiveEntryFail(error)))
39+
catchError((error) => {
40+
this.toastrService.success(error);
41+
return of(new actions.LoadActiveEntryFail(error));
42+
})
3743
)
3844
)
3945
);
@@ -44,7 +50,10 @@ export class EntryEffects {
4450
mergeMap(() =>
4551
this.entryService.loadEntries().pipe(
4652
map((entries) => new actions.LoadEntriesSuccess(entries)),
47-
catchError((error) => of(new actions.LoadEntriesFail(error)))
53+
catchError((error) => {
54+
this.toastrService.success(error);
55+
return of(new actions.LoadEntriesFail(error));
56+
})
4857
)
4958
)
5059
);
@@ -64,7 +73,7 @@ export class EntryEffects {
6473
return new actions.CreateEntrySuccess(entryData);
6574
}),
6675
catchError((error) => {
67-
this.toastrService.error(UNEXPECTED_ERROR);
76+
this.toastrService.error(error.error.message);
6877
return of(new actions.CreateEntryFail(error.error.message));
6978
})
7079
)
@@ -82,7 +91,7 @@ export class EntryEffects {
8291
return new actions.DeleteEntrySuccess(entryId);
8392
}),
8493
catchError((error) => {
85-
this.toastrService.error(UNEXPECTED_ERROR);
94+
this.toastrService.error(error.error.message);
8695
return of(new actions.DeleteEntryFail(error));
8796
})
8897
)
@@ -99,7 +108,7 @@ export class EntryEffects {
99108
return new actions.UpdateActiveEntrySuccess(projectData);
100109
}),
101110
catchError((error) => {
102-
this.toastrService.error(UNEXPECTED_ERROR);
111+
this.toastrService.error(error.error.message);
103112
return of(new actions.UpdateActiveEntryFail(error));
104113
})
105114
)
@@ -116,7 +125,10 @@ export class EntryEffects {
116125
this.toastrService.success('You clocked-out successfully');
117126
return new actions.StopTimeEntryRunningSuccess(timeEntryId);
118127
}),
119-
catchError((error) => of(new actions.StopTimeEntryRunningFail(error.error.message)))
128+
catchError((error) => {
129+
this.toastrService.error(error.error.message);
130+
return of(new actions.StopTimeEntryRunningFail(error.error.message));
131+
})
120132
)
121133
)
122134
);

0 commit comments

Comments
 (0)