From 0b6915922230477485c47e4fdcdeeca1e93e4fdd Mon Sep 17 00:00:00 2001
From: paf <paf@titelfrei.de>
Date: Mon, 14 Jun 2021 12:23:22 +0200
Subject: [PATCH] Make error-handling more consistent and expressive: In case
 of malformed serverUrl (like with missing trailing slash in docker-network)
 the error of type DOMException was swallowed completely.

---
 src/app/app.component.ts     |  9 +++++----
 src/app/app.interceptor.ts   | 18 +++++++++++++++++-
 src/app/config/app.config.ts |  3 ++-
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index b2613003..63bf7329 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -65,10 +65,6 @@ export class AppComponent implements OnInit, OnDestroy {
       this.setupFocusListeners();
 
       this.bs.getSysConfig().subscribe(sysConfig => {
-        this.mds.appConfig = new AppConfig(sysConfig, this.cts, this.mds.expectedApiVersion, this.sanitizer);
-        this.mds.appTitle$.next(this.mds.appConfig.appTitle);
-        this.mds.appConfig.applyBackgroundColors();
-        this.mds.globalWarning = this.mds.appConfig.warningMessage;
         if (!sysConfig) {
           this.mds.appError$.next({
             label: 'Server-Problem: Konnte Konfiguration nicht laden',
@@ -77,6 +73,11 @@ export class AppComponent implements OnInit, OnDestroy {
           });
           return;
         }
+        this.mds.appConfig = new AppConfig(sysConfig, this.cts, this.mds.expectedApiVersion, this.sanitizer);
+        this.mds.appTitle$.next(this.mds.appConfig.appTitle);
+        this.mds.appConfig.applyBackgroundColors();
+        this.mds.globalWarning = this.mds.appConfig.warningMessage;
+
         const authData = MainDataService.getAuthData();
         if (authData) {
           this.cts.addCustomTexts(authData.customTexts);
diff --git a/src/app/app.interceptor.ts b/src/app/app.interceptor.ts
index d17d9522..e0848c43 100644
--- a/src/app/app.interceptor.ts
+++ b/src/app/app.interceptor.ts
@@ -37,7 +37,7 @@ export class AuthInterceptor implements HttpInterceptor {
       return next.handle(requestA).pipe(
         catchError(error => {
           const apiError = new ApiError(999);
-          if (error instanceof HttpErrorResponse) { // TODO is the opposite case even possible?
+          if (error instanceof HttpErrorResponse) {
             const httpError = error as HttpErrorResponse;
             apiError.code = httpError.status;
             apiError.info = `${httpError.message} // ${httpError.error}`;
@@ -112,6 +112,22 @@ export class AuthInterceptor implements HttpInterceptor {
                 }
               }
             }
+
+          } else if (error instanceof DOMException) {
+            apiError.info = `Fehler: ${error.name} // ${error.message}`
+            this.mds.appError$.next({
+              label: `Fehler: ${error.name}`,
+              description: error.message,
+              category: 'PROBLEM'
+            });
+
+          } else {
+            apiError.info = 'Unbekannter Fehler';
+            this.mds.appError$.next({
+              label: 'Unbekannter Fehler',
+              description: '',
+              category: 'PROBLEM'
+            });
           }
 
           return throwError(apiError);
diff --git a/src/app/config/app.config.ts b/src/app/config/app.config.ts
index 4ab3b7dc..08e255ab 100644
--- a/src/app/config/app.config.ts
+++ b/src/app/config/app.config.ts
@@ -74,8 +74,9 @@ export class AppConfig {
   ) {
     this.sanitizer = sanitizer;
     this.cts = cts;
-    this.customTexts = sysConfig.customTexts;
+
     if (sysConfig) {
+      this.customTexts = sysConfig.customTexts;
       this.setCustomTexts(sysConfig.customTexts);
       this.setAppConfig(sysConfig.appConfig);
       this.testConfig = sysConfig.testConfig;
-- 
GitLab