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

fix(error): resolve error handler issues (DEV-938) #744

Merged
merged 7 commits into from May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
18 changes: 10 additions & 8 deletions src/app/main/services/error-handler.service.ts
@@ -1,5 +1,5 @@
import { Inject, Injectable } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
import { ApiResponseData, ApiResponseError, HealthResponse, KnoraApiConnection, LogoutResponse } from '@dasch-swiss/dsp-js';
import { HttpStatusMsg } from 'src/assets/http/statusMsg';
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
Expand All @@ -12,6 +12,8 @@ import { SessionService } from '../services/session.service';
})
export class ErrorHandlerService {

dialogRef: MatDialogRef<any>;

constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _notification: NotificationService,
Expand Down Expand Up @@ -66,11 +68,12 @@ export class ErrorHandlerService {
disableClose: true
};

this._dialog.open(
DialogComponent,
dialogConfig
);

if (!this.dialogRef) {
this.dialogRef = this._dialog.open(
DialogComponent,
dialogConfig
);
}

} else if (error.status === 401 && typeof(error.error) !== 'string') {
// logout if error status is a 401 error and comes from a DSP-JS request
Expand All @@ -90,8 +93,7 @@ export class ErrorHandlerService {
);

} else {
// in any other case
// open snack bar from dsp-ui notification service
// open snack bar in any other case
this._notification.openSnackBar(error);
// log error to Rollbar (done automatically by simply throwing a new Error)
if (error instanceof ApiResponseError) {
Expand Down
29 changes: 16 additions & 13 deletions src/app/main/services/notification.service.ts
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { ApiResponseError } from '@dasch-swiss/dsp-js';
import { HttpStatusMsg } from 'src/assets/http/statusMsg';

Expand All @@ -17,16 +17,22 @@ export class NotificationService {
// action: string = 'x', duration: number = 4200
// and / or type: 'note' | 'warning' | 'error' | 'success'; which can be used for the panelClass
openSnackBar(notification: string | ApiResponseError, type?: 'success' | 'error'): void {
let duration = 5000;
// let duration = 5000;
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
let message: string;
let panelClass: string;
// let panelClass: string;
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved

const conf: MatSnackBarConfig = {
duration: 5000,
horizontalPosition: 'center',
verticalPosition: 'top',
panelClass: type ? type : 'error',
};

if (notification instanceof ApiResponseError) {
panelClass = type ? type : 'error';
conf.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}): `;
Expand All @@ -35,21 +41,18 @@ export class NotificationService {
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;
conf.duration = null;
} else {
message += `${defaultStatusMsg[notification.status].description}`;
}
}
} else {
panelClass = type ? type : 'success';
conf.panelClass = type ? type : 'success';
message = notification;
}

this._snackBar.open(message, 'x', {
duration,
horizontalPosition: 'center',
verticalPosition: 'top',
panelClass
});
this._snackBar.open(message, 'x', conf);

this._snackBar.dismiss();
}
}
4 changes: 2 additions & 2 deletions src/app/workspace/resource/resource.component.html
@@ -1,5 +1,5 @@
<div class="content large middle">
<div class="resource-view">
<div class="resource-view" *ngIf="resource">

<!-- dsp-resource-representation -->
<div class="representation-container center" *ngIf="representationsToDisplay.length && representationsToDisplay[0].fileValue"
Expand Down Expand Up @@ -114,7 +114,7 @@

<!-- resource not found -->
<div *ngIf="!resource && !loading" class="no-results">
<p>The resource <span *ngIf="resourceIri">- <strong> {{resourceIri}}</strong> -</span> could not
<p>The resource <span *ngIf="resourceIri">&mdash; <strong> {{resourceIri}}</strong> &mdash;</span> could not
be found.</p>
<p>Reasons:</p>
<ul>
Expand Down
9 changes: 2 additions & 7 deletions src/app/workspace/resource/resource.component.ts
Expand Up @@ -289,14 +289,9 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {
// this.loading = false;
},
(error: ApiResponseError) => {
this.resource = undefined;
this.loading = false;
if (error.status === 404) {
// resource not found
// display message that it couldn't be found
this.resource = undefined;
} else {
this._errorHandler.showMessage(error);
}
this._errorHandler.showMessage(error);
}
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/workspace/results/list-view/list-view.component.ts
Expand Up @@ -159,8 +159,8 @@ export class ListViewComponent implements OnChanges {
}
},
(countError: ApiResponseError) => {
this._errorHandler.showMessage(countError);
this.loading = countError.status !== 504;
this._errorHandler.showMessage(countError);
}
);
}
Expand All @@ -177,9 +177,9 @@ export class ListViewComponent implements OnChanges {
this.loading = false;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
this.resources = undefined;
this.loading = false;
this.resources = undefined;
this._errorHandler.showMessage(error);
}
);

Expand All @@ -201,8 +201,8 @@ export class ListViewComponent implements OnChanges {
}
},
(countError: ApiResponseError) => {
this._errorHandler.showMessage(countError);
this.loading = countError.status !== 504;
this._errorHandler.showMessage(countError);
}
);
}
Expand All @@ -224,9 +224,9 @@ export class ListViewComponent implements OnChanges {
this.loading = false;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
this.resources = undefined;
this.loading = false;
this.resources = undefined;
this._errorHandler.showMessage(error);
}
);
} else {
Expand Down