From 34f283b3d8af0793d4c5b0ff27c02b3992954b1f Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Fri, 5 Jun 2020 12:42:27 +1000
Subject: [PATCH] cleanup some of the notifications. Hopefully we will now see
 all notifications correctly and failing that get useful info in the
 javascript console

---
 src/app/backend-selection.service.ts | 13 ++++++++++++-
 src/app/browser-window.service.ts    |  8 ++++++--
 src/app/jobs.service.ts              |  8 ++++----
 src/app/notifications.service.ts     | 11 ++++++++++-
 src/app/tes.service.ts               | 19 +++----------------
 5 files changed, 35 insertions(+), 24 deletions(-)

diff --git a/src/app/backend-selection.service.ts b/src/app/backend-selection.service.ts
index b06ed2c..224df91 100644
--- a/src/app/backend-selection.service.ts
+++ b/src/app/backend-selection.service.ts
@@ -32,6 +32,11 @@ export class BackendSelectionService {
     if (s.tes.indexOf('localhost') == -1) {
       return true;
     } else {
+      if (s.ping === null ) {
+        return false;
+      } else {
+        return true;
+      }
     }
   }
   private updateApiServer(apiservers: APIServer[]) {
@@ -59,6 +64,12 @@ export class BackendSelectionService {
       if (nextserver === undefined) {
         nextserver = apiservers[0]
       }
+
+      if (nextserver !== undefined && nextserver !== null && nextserver.tes.indexOf('localhost') != -1) {
+        this.localapi.next(true);
+      } else {
+        this.localapi.next(false);
+      }
       this.apiserver.next(nextserver);
     }
   }
@@ -75,7 +86,7 @@ export class BackendSelectionService {
       this.http.get<string>(server.tes+'/sshagent',options).pipe(
         timeout(timeouts))])
       .subscribe((ok) => {server.ping = (performance.now() - <number>(ok[0]))},
-                 (err) => {server.ping = undefined});
+                 (err) => {server.ping = null});
     }
   }
 
diff --git a/src/app/browser-window.service.ts b/src/app/browser-window.service.ts
index 37f90f1..8670905 100644
--- a/src/app/browser-window.service.ts
+++ b/src/app/browser-window.service.ts
@@ -109,13 +109,17 @@ export class BrowserWindowService {
 
   public logUsage() {
     var app: any;
+    console.log('entered log usage');
+    console.log(this.settingsService.logging);
     if (this.settingsService.logging) {
     this.openapps.forEach( (app,index) => {
+      console.log('probing window',app);
       if (!app.window.closed) {
         if (app.job.state == 'RUNNING') {
+          console.log('log url',environment.logserver+"/"+app.job.identity.site.name+"/"+app.job.identity.username+"/"+app.job.app.name+"/"+app.job.jobid);
           this.http.get<any>(environment.logserver+"/"+app.job.identity.site.name+"/"+app.job.identity.username+"/"+app.job.app.name+"/"+app.job.jobid).pipe( //We're expecting 404 not founds
-            catchError((e) => {return of([]);})
-          ).subscribe((_) => {return})
+            catchError((e) => {console.error(e); return of([]);})
+          ).subscribe((v) => {console.log('log success',v); return})
         }
       }
     })
diff --git a/src/app/jobs.service.ts b/src/app/jobs.service.ts
index 0b6cf6c..b244cac 100644
--- a/src/app/jobs.service.ts
+++ b/src/app/jobs.service.ts
@@ -46,11 +46,11 @@ export class JobsService {
       if (error.error.message.indexOf("Permission denied") != -1) {
         this.notifications.notify("Your login appears to have expired. Please log in again");
         this.authService.updateAgentContents().subscribe((_) => {return});
-      } else {
-        this.notifications.notify(error.error.message);
-      }
-      return;
+        return;
+      } 
     }
+    this.notifications.notify("Unable to retrieve a list of running jobs.\nDid your session expire?")
+    console.error(error);
     this.authService.updateAgentContents().subscribe((_) => {return});
   }
 
diff --git a/src/app/notifications.service.ts b/src/app/notifications.service.ts
index 5c28182..58496d7 100644
--- a/src/app/notifications.service.ts
+++ b/src/app/notifications.service.ts
@@ -16,8 +16,17 @@ export class NotificationsService {
     return this.msg;
   }
 
-  notify(msg: string) {
+  notify(msg: any) {
+    if (msg.hasOwnProperty('error')) {
+      this.notify(msg.error);
+      return;
+    }
+    if (msg.hasOwnProperty('message')) {
+      this.notify(msg.message);
+      return;
+    }
     this.msg.next(msg);
+    console.log(msg);
   }
 
 
diff --git a/src/app/tes.service.ts b/src/app/tes.service.ts
index ff3348e..5d220e5 100644
--- a/src/app/tes.service.ts
+++ b/src/app/tes.service.ts
@@ -159,9 +159,7 @@ private addUserHealth(identity,resp) {
      return
    }
    if (error.status == 400) {
-       if (error.error !== undefined && error.error.message !== undefined) {
-        this.notifications.notify(error.error.message);
-       }
+       this.notifications.notify(error);
        return
    }
  }
@@ -170,35 +168,24 @@ private addUserHealth(identity,resp) {
  submissionError(error: any) {
    if (error.status != 0) {
        try {
-         this.notifications.notify(error.error);
+         this.notifications.notify(error);
          console.error(error);
        } catch {
          this.notifications.notify('Job Canceling failed');
          console.error(error);
        }
-       /*if ('error' in error && 'message' in error.error) {
-         this.notifications.notify(error.error.message);
-       } else {
-         this.notifications.notify('Job submission failed');
-       }*/
    }
  }
 
  cancelError(error: any) {
    if (error.status != 0) {
        try {
-         this.notifications.notify(error.error);
+         this.notifications.notify(error);
          console.error(error);
        } catch {
          this.notifications.notify('Job Canceling failed');
          console.error(error);
        }
-
-       /*if ('error' in error && 'message' in error.error) {
-         this.notifications.notify(error.error.message);
-       } else {
-         this.notifications.notify('Job Canceling failed');
-       }*/
    }
  }
 
-- 
GitLab