From 0eb621bbf9aa182d17b09df3ead46c34d357e0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Wed, 22 Sep 2021 09:27:03 +0200 Subject: [PATCH] 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 --- src/app/main/error/error-handler.service.ts | 8 ++++++-- src/app/main/services/notification.service.ts | 13 +++++++++---- src/app/workspace/resource/resource.component.html | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/app/main/error/error-handler.service.ts b/src/app/main/error/error-handler.service.ts index e7343294be..7b94467328 100644 --- a/src/app/main/error/error-handler.service.ts +++ b/src/app/main/error/error-handler.service.ts @@ -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 = { diff --git a/src/app/main/services/notification.service.ts b/src/app/main/services/notification.service.ts index c361b653dc..0d4fb9e08d 100644 --- a/src/app/main/services/notification.service.ts +++ b/src/app/main/services/notification.service.ts @@ -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; diff --git a/src/app/workspace/resource/resource.component.html b/src/app/workspace/resource/resource.component.html index eab28bc86b..50d6832bf0 100644 --- a/src/app/workspace/resource/resource.component.html +++ b/src/app/workspace/resource/resource.component.html @@ -76,6 +76,7 @@

Reasons: