From f60587ff389c1ce3fc8dfbc09d28ad83c4508062 Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Sat, 16 Mar 2019 21:15:09 +1100
Subject: [PATCH] error initialising the apiserver the localstorage as a value
 null

---
 src/app/authorisation.service.ts     | 2 +-
 src/app/backend-selection.service.ts | 5 +++++
 src/app/tes.service.ts               | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/app/authorisation.service.ts b/src/app/authorisation.service.ts
index 46137e2..710730f 100644
--- a/src/app/authorisation.service.ts
+++ b/src/app/authorisation.service.ts
@@ -59,7 +59,7 @@ export class AuthorisationService {
                 this.keys = [];
                 this.getSshAuthzServers();
                 this.keys = [];
-                this.backendSelectionService.apiserver.subscribe((value) => { this.backendURI = value.tes ; this.updateAgentContents() })
+      this.backendSelectionService.apiserver.subscribe((value) => { if (value != null) {this.backendURI = value.tes ; this.updateAgentContents()} })
       this.agentContents.subscribe((value) => this.updateLoggedAuthZ());
       this.sshAuthzServers.subscribe((value) => this.updateLoggedAuthZ());
  }
diff --git a/src/app/backend-selection.service.ts b/src/app/backend-selection.service.ts
index a457110..615e18f 100644
--- a/src/app/backend-selection.service.ts
+++ b/src/app/backend-selection.service.ts
@@ -22,8 +22,13 @@ export class BackendSelectionService {
     private initApiServer() {
         try {
             this.apiserver.next(<APIServer>JSON.parse(localStorage.getItem('apiserver')));
+            console.log('apiserver set to localstorage value',this.apiserver.value);
         } catch {
             this.apiserver.next(<APIServer>environment.apiserver);
+            console.log('api server to set environement',this.apiserver.value);
+        }
+        if (this.apiserver.value == null) {
+            this.apiserver.next(<APIServer>environment.apiserver);
         }
     }
 
diff --git a/src/app/tes.service.ts b/src/app/tes.service.ts
index 6e305d1..c722782 100644
--- a/src/app/tes.service.ts
+++ b/src/app/tes.service.ts
@@ -67,7 +67,7 @@ public apiservers: BehaviorSubject<APIServer[]>;
 
     this.timerSubscription = null;
     this.appwindowWatcher = null;
-    this.backendSelectionService.apiserver.subscribe( (value) => { this.twsproxy = value.tws ; this.Base = value.tes });
+      this.backendSelectionService.apiserver.subscribe( (value) => { if (value != null) {this.twsproxy = value.tws ; this.Base = value.tes }});
     // this.batchinterface = {};
     // this.computesitesService.identities.subscribe(identities => this.startPolling(identities));
  }
-- 
GitLab