Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(error): handle 504 timeout error with snackbar (DEV-751) #739

Merged
merged 2 commits into from May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/main/services/error-handler.service.ts
Expand Up @@ -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);

Expand Down
15 changes: 12 additions & 3 deletions src/app/main/services/notification.service.ts
Expand Up @@ -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', {
Expand Down
14 changes: 8 additions & 6 deletions src/app/workspace/resource/resource.component.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -270,6 +272,7 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {
}
},
(error: ApiResponseError) => {
this.loading = false;
this._errorHandler.showMessage(error);
}
);
Expand All @@ -294,7 +297,6 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {
} else {
this._errorHandler.showMessage(error);
}

}
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/workspace/results/list-view/list-view.component.ts
Expand Up @@ -103,6 +103,7 @@ export class ListViewComponent implements OnChanges {
this.pageEvent = new PageEvent();
this.pageEvent.pageIndex = 0;
this.resources = undefined;
this.emitSelectedResources();

this._doSearch();
}
Expand Down Expand Up @@ -159,6 +160,7 @@ export class ListViewComponent implements OnChanges {
},
(countError: ApiResponseError) => {
this._errorHandler.showMessage(countError);
this.loading = countError.status !== 504;
}
);
}
Expand Down Expand Up @@ -200,6 +202,7 @@ export class ListViewComponent implements OnChanges {
},
(countError: ApiResponseError) => {
this._errorHandler.showMessage(countError);
this.loading = countError.status !== 504;
}
);
}
Expand Down
Expand Up @@ -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';

Expand Down