Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(error): improve the current error handler in DSP-APP (DSP-1911) (#…
…540)

* chore(error): use correct error status values

* chore(error): better js-lib error message handling

* chore(error): better error handler

* test(error): fix error handler
  • Loading branch information
kilchenmann committed Sep 22, 2021
1 parent 67a52a3 commit 0eb621b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/app/main/error/error-handler.service.ts
Expand Up @@ -19,9 +19,13 @@ export class ErrorHandlerService {
) { }

showMessage(error: ApiResponseError) {

// in case of (internal) server error
if (error.status === 0 || (error.status > 499 && error.status < 600)) {
const status = (error.status === 0 ? 503 : error.status);
const apiServerError = (error.error && error.error['response'] && error.error['response'] === null);

if ((error.status > 499 && error.status < 600) || apiServerError) {

const status = (apiServerError ? 503 : error.status);

// open error message in full size view
const dialogConfig: MatDialogConfig = {
Expand Down
13 changes: 9 additions & 4 deletions src/app/main/services/notification.service.ts
Expand Up @@ -17,14 +17,19 @@ 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): void {
const duration = 5000;
let duration = 5000;
let message: string;
let panelClass: string;

if (notification instanceof ApiResponseError) {
const status = (notification.status === 0 ? 503 : notification.status);
const defaultStatusMsg = this._statusMsg.default;
message = `${defaultStatusMsg[status].message} (${status}): ${defaultStatusMsg[status].description}`;
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}`;
}
panelClass = 'error';
} else {
message = notification;
Expand Down
1 change: 1 addition & 0 deletions src/app/workspace/resource/resource.component.html
Expand Up @@ -76,6 +76,7 @@
<p>Reasons:</p>
<ul>
<li>It could be a deleted resource and does not exist anymore.</li>
<li>You don't have the permissions to open this resource.</li>
<li>The identifier or the ARK URL is wrong.</li>
</ul>
</div>
Expand Down

0 comments on commit 0eb621b

Please sign in to comment.