Skip to content
Snippets Groups Projects
Commit dfb4a3bd authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

54472: Notification errors

parent 12058cb4
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,8 @@ export class CollectionDataService extends ComColDataService<NormalizedCollectio
protected cds: CommunityDataService,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected authService: AuthService
protected authService: AuthService,
protected notificationsService: NotificationsService
) {
super();
}
......
......@@ -36,6 +36,7 @@ class TestService extends ComColDataService<NormalizedTestObject, any> {
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected authService: AuthService,
protected notificationsService: NotificationsService,
protected linkPath: string
) {
super();
......
......@@ -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<NormalizedCommunity, Community> {
......@@ -30,7 +31,8 @@ export class CommunityDataService extends ComColDataService<NormalizedCommunity,
protected store: Store<CoreState>,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected authService: AuthService
protected authService: AuthService,
protected notificationsService: NotificationsService
) {
super();
}
......
......@@ -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<NormalizedTestObject, any> {
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>,
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<CoreState>;
const endpoint = 'https://rest.api/core';
......@@ -51,7 +54,8 @@ describe('DataService', () => {
rdbService,
store,
LINK_NAME,
halService
halService,
notificationsService
);
}
......
......@@ -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<TNormalized extends NormalizedObject, TDomain> {
protected abstract responseCache: ResponseCacheService;
......@@ -41,6 +43,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
protected abstract linkPath: string;
protected abstract halService: HALEndpointService;
protected abstract authService: AuthService;
protected abstract notificationsService: NotificationsService;
public abstract getScopedEndpoint(scope: string): Observable<string>
......@@ -140,6 +143,13 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
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<TDomain>) => response.payload),
......
......@@ -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<NormalizedDSpaceObject, DSpaceObject> {
......@@ -22,7 +23,8 @@ class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject>
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>,
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<RemoteData<DSpaceObject>> {
......
......@@ -29,7 +29,8 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
protected store: Store<CoreState>,
private bs: BrowseService,
protected halService: HALEndpointService,
protected authService: AuthService) {
protected authService: AuthService,
protected notificationsService: NotificationsService) {
super();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment