From 8f6c4092f12e53e6a831968b1fd451c0bec30d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 16 May 2022 09:42:22 +0200 Subject: [PATCH] feat(error): handle 504 timeout error with snackbar (DEV-751) (#739) --- src/app/main/services/error-handler.service.ts | 2 +- src/app/main/services/notification.service.ts | 15 ++++++++++++--- src/app/workspace/resource/resource.component.ts | 14 ++++++++------ .../results/list-view/list-view.component.ts | 3 +++ .../fulltext-search/fulltext-search.component.ts | 3 +-- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/app/main/services/error-handler.service.ts b/src/app/main/services/error-handler.service.ts index c04874c79f..36d0046e3b 100644 --- a/src/app/main/services/error-handler.service.ts +++ b/src/app/main/services/error-handler.service.ts @@ -27,7 +27,7 @@ export class ErrorHandlerService { const apiResponseMessage = (error.error['response'] ? error.error['response'].error : undefined); - if ((error.status > 499 && error.status < 600) || apiServerError) { + if (((error.status > 499 && error.status < 600) || apiServerError) && error.status !== 504) { let status = (apiServerError ? 503 : error.status); diff --git a/src/app/main/services/notification.service.ts b/src/app/main/services/notification.service.ts index baae49b343..4e70446c04 100644 --- a/src/app/main/services/notification.service.ts +++ b/src/app/main/services/notification.service.ts @@ -22,18 +22,27 @@ export class NotificationService { let panelClass: string; if (notification instanceof ApiResponseError) { + panelClass = type ? type : 'error'; if (notification.error && !notification.error['message'].startsWith('ajax error')) { // the Api response error contains a complex error message from dsp-js-lib message = notification.error['message']; duration = undefined; } else { const defaultStatusMsg = this._statusMsg.default; - message = `${defaultStatusMsg[notification.status].message} (${notification.status}): ${defaultStatusMsg[notification.status].description}`; + message = `${defaultStatusMsg[notification.status].message} (${notification.status}): `; + + if (notification.status === 504) { + message += `There was a timeout issue with one or several requests. + The resource(s) or a part of it cannot be displayed correctly. + Failed on ${notification.url}`; + duration = undefined; + } else { + message += `${defaultStatusMsg[notification.status].description}`; + } } - panelClass = type ? type : 'error'; } else { - message = notification; panelClass = type ? type : 'success'; + message = notification; } this._snackBar.open(message, 'x', { diff --git a/src/app/workspace/resource/resource.component.ts b/src/app/workspace/resource/resource.component.ts index c6bfea7969..a8beb51184 100644 --- a/src/app/workspace/resource/resource.component.ts +++ b/src/app/workspace/resource/resource.component.ts @@ -12,13 +12,17 @@ import { import { ApiResponseError, Constants, - CountQueryResponse, IHasPropertyWithPropertyDefinition, + CountQueryResponse, + IHasPropertyWithPropertyDefinition, KnoraApiConnection, ReadArchiveFileValue, ReadAudioFileValue, - ReadDocumentFileValue, ReadMovingImageFileValue, ReadResource, + ReadDocumentFileValue, + ReadMovingImageFileValue, + ReadResource, ReadResourceSequence, - ReadStillImageFileValue, SystemPropertyDefinition + ReadStillImageFileValue, + SystemPropertyDefinition } from '@dasch-swiss/dsp-js'; import { Subscription } from 'rxjs'; import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; @@ -134,8 +138,6 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy { } if (event instanceof NavigationError) { - // hide loading indicator - // present error to user this._errorHandler.showMessage(event.error); @@ -270,6 +272,7 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy { } }, (error: ApiResponseError) => { + this.loading = false; this._errorHandler.showMessage(error); } ); @@ -294,7 +297,6 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy { } else { this._errorHandler.showMessage(error); } - } ); } diff --git a/src/app/workspace/results/list-view/list-view.component.ts b/src/app/workspace/results/list-view/list-view.component.ts index 190c4acb57..ccfca6d6b5 100644 --- a/src/app/workspace/results/list-view/list-view.component.ts +++ b/src/app/workspace/results/list-view/list-view.component.ts @@ -103,6 +103,7 @@ export class ListViewComponent implements OnChanges { this.pageEvent = new PageEvent(); this.pageEvent.pageIndex = 0; this.resources = undefined; + this.emitSelectedResources(); this._doSearch(); } @@ -159,6 +160,7 @@ export class ListViewComponent implements OnChanges { }, (countError: ApiResponseError) => { this._errorHandler.showMessage(countError); + this.loading = countError.status !== 504; } ); } @@ -200,6 +202,7 @@ export class ListViewComponent implements OnChanges { }, (countError: ApiResponseError) => { this._errorHandler.showMessage(countError); + this.loading = countError.status !== 504; } ); } diff --git a/src/app/workspace/search/fulltext-search/fulltext-search.component.ts b/src/app/workspace/search/fulltext-search/fulltext-search.component.ts index d84097b6a9..f5990a356d 100644 --- a/src/app/workspace/search/fulltext-search/fulltext-search.component.ts +++ b/src/app/workspace/search/fulltext-search/fulltext-search.component.ts @@ -26,9 +26,8 @@ import { } from '@dasch-swiss/dsp-js'; import { Subscription } from 'rxjs'; import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens'; -import { ErrorHandlerService } from 'src/app/main/services/error-handler.service'; import { ComponentCommunicationEventService, Events } from 'src/app/main/services/component-communication-event.service'; -import { NotificationService } from 'src/app/main/services/notification.service'; +import { ErrorHandlerService } from 'src/app/main/services/error-handler.service'; import { SortingService } from 'src/app/main/services/sorting.service'; import { SearchParams } from '../../results/list-view/list-view.component';