From dfb4a3bd9c28889f7599a86d03f03477256440c1 Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Tue, 11 Sep 2018 09:21:35 +0200 Subject: [PATCH] 54472: Notification errors --- src/app/core/data/collection-data.service.ts | 3 ++- src/app/core/data/comcol-data.service.spec.ts | 1 + src/app/core/data/community-data.service.ts | 4 +++- src/app/core/data/data.service.spec.ts | 8 ++++++-- src/app/core/data/data.service.ts | 12 +++++++++++- src/app/core/data/dspace-object-data.service.ts | 9 ++++++--- src/app/core/data/item-data.service.ts | 3 ++- 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index dc3635595a..fd2404650f 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -27,7 +27,8 @@ export class CollectionDataService extends ComColDataService { protected objectCache: ObjectCacheService, protected halService: HALEndpointService, protected authService: AuthService, + protected notificationsService: NotificationsService, protected linkPath: string ) { super(); diff --git a/src/app/core/data/community-data.service.ts b/src/app/core/data/community-data.service.ts index 4570e749d8..4689fac854 100644 --- a/src/app/core/data/community-data.service.ts +++ b/src/app/core/data/community-data.service.ts @@ -16,6 +16,7 @@ import { RemoteData } from './remote-data'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { Observable } from 'rxjs/Observable'; import { PaginatedList } from './paginated-list'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; @Injectable() export class CommunityDataService extends ComColDataService { @@ -30,7 +31,8 @@ export class CommunityDataService extends ComColDataService, protected objectCache: ObjectCacheService, protected halService: HALEndpointService, - protected authService: AuthService + protected authService: AuthService, + protected notificationsService: NotificationsService ) { super(); } diff --git a/src/app/core/data/data.service.spec.ts b/src/app/core/data/data.service.spec.ts index 8377afe92e..8abf4e51ca 100644 --- a/src/app/core/data/data.service.spec.ts +++ b/src/app/core/data/data.service.spec.ts @@ -9,6 +9,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service'; import { Observable } from 'rxjs/Observable'; import { FindAllOptions } from './request.models'; import { SortOptions, SortDirection } from '../cache/models/sort-options.model'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; const LINK_NAME = 'test' @@ -23,7 +24,8 @@ class TestService extends DataService { protected rdbService: RemoteDataBuildService, protected store: Store, protected linkPath: string, - protected halService: HALEndpointService + protected halService: HALEndpointService, + protected notificationsService: NotificationsService ) { super(); } @@ -41,6 +43,7 @@ describe('DataService', () => { const requestService = {} as RequestService; const halService = {} as HALEndpointService; const rdbService = {} as RemoteDataBuildService; + const notificationsService = {} as NotificationsService; const store = {} as Store; const endpoint = 'https://rest.api/core'; @@ -51,7 +54,8 @@ describe('DataService', () => { rdbService, store, LINK_NAME, - halService + halService, + notificationsService ); } diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index a29cb7877f..9d7422cbe1 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -28,10 +28,12 @@ import { import { ResponseCacheEntry } from '../cache/response-cache.reducer'; import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; import { HttpHeaders } from '@angular/common/http'; -import { DSOSuccessResponse, GenericSuccessResponse } from '../cache/response-cache.models'; +import { DSOSuccessResponse, ErrorResponse, GenericSuccessResponse } from '../cache/response-cache.models'; import { AuthService } from '../auth/auth.service'; import { Collection } from '../shared/collection.model'; import { Community } from '../shared/community.model'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; +import { NotificationOptions } from '../../shared/notifications/models/notification-options.model'; export abstract class DataService { protected abstract responseCache: ResponseCacheService; @@ -41,6 +43,7 @@ export abstract class DataService protected abstract linkPath: string; protected abstract halService: HALEndpointService; protected abstract authService: AuthService; + protected abstract notificationsService: NotificationsService; public abstract getScopedEndpoint(scope: string): Observable @@ -140,6 +143,13 @@ export abstract class DataService const payload$ = request$.pipe( map((request: RestRequest) => request.href), getResponseFromSelflink(this.responseCache), + map((response: ResponseCacheEntry) => { + if (!response.response.isSuccessful && response.response instanceof ErrorResponse) { + const errorResponse: ErrorResponse = response.response; + this.notificationsService.error('Server Error:', errorResponse.errorMessage, new NotificationOptions(-1)); + } + return response; + }), filterSuccessfulResponses(), map((entry: ResponseCacheEntry) => entry.response), map((response: GenericSuccessResponse) => response.payload), diff --git a/src/app/core/data/dspace-object-data.service.ts b/src/app/core/data/dspace-object-data.service.ts index bf2da345b8..eb657e1737 100644 --- a/src/app/core/data/dspace-object-data.service.ts +++ b/src/app/core/data/dspace-object-data.service.ts @@ -11,6 +11,7 @@ import { DataService } from './data.service'; import { RemoteData } from './remote-data'; import { RequestService } from './request.service'; import { AuthService } from '../auth/auth.service'; +import { NotificationsService } from '../../shared/notifications/notifications.service'; /* tslint:disable:max-classes-per-file */ class DataServiceImpl extends DataService { @@ -22,7 +23,8 @@ class DataServiceImpl extends DataService protected rdbService: RemoteDataBuildService, protected store: Store, protected halService: HALEndpointService, - protected authService: AuthService) { + protected authService: AuthService, + protected notificationsService: NotificationsService) { super(); } @@ -48,8 +50,9 @@ export class DSpaceObjectDataService { protected requestService: RequestService, protected rdbService: RemoteDataBuildService, protected halService: HALEndpointService, - protected authService: AuthService) { - this.dataService = new DataServiceImpl(null, requestService, rdbService, null, halService, authService); + protected authService: AuthService, + protected notificationsService: NotificationsService) { + this.dataService = new DataServiceImpl(null, requestService, rdbService, null, halService, authService, notificationsService); } findById(uuid: string): Observable> { diff --git a/src/app/core/data/item-data.service.ts b/src/app/core/data/item-data.service.ts index d1db71b78d..448d3fc84b 100644 --- a/src/app/core/data/item-data.service.ts +++ b/src/app/core/data/item-data.service.ts @@ -29,7 +29,8 @@ export class ItemDataService extends DataService { protected store: Store, private bs: BrowseService, protected halService: HALEndpointService, - protected authService: AuthService) { + protected authService: AuthService, + protected notificationsService: NotificationsService) { super(); }