better error handling
authorJason Etheridge <jason@EquinoxInitiative.org>
Mon, 11 Nov 2019 20:00:48 +0000 (15:00 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 16 Jan 2020 21:38:28 +0000 (16:38 -0500)
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-clone-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-create-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-delete-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/acq/search/picklist-merge-dialog.component.ts

index dd9317a..63996dc 100644 (file)
@@ -1,7 +1,9 @@
 import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
 import {Observable, from, empty, throwError} from 'rxjs';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
@@ -20,8 +22,11 @@ export class PicklistCloneDialogComponent
   leadListName: String;
   selections: IdlObject[];
 
+  @ViewChild('fail', { static: true }) private fail: AlertDialogComponent;
+
   constructor(
     private idl: IdlService,
+    private evt: EventService,
     private net: NetService,
     private auth: AuthService,
     private modal: NgbModal
@@ -47,8 +52,19 @@ export class PicklistCloneDialogComponent
       this.grid.context.getSelectedRows()[0].id(),
       this.selectionListName
     ).subscribe(
-      new_id => this.close(new_id),
-      err => throwError(err)
+      (res) => {
+        if (this.evt.parse(res)) {
+          console.error(res);
+          this.fail.open();
+        } else {
+          console.log(res);
+        }
+      },
+      (err) => {
+        console.error(err);
+        this.fail.open();
+      },
+      () => this.close(true)
     );
   }
 }
index 380b9fc..2325aae 100644 (file)
@@ -1,7 +1,9 @@
 import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
 import {Observable, from, empty, throwError} from 'rxjs';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
@@ -17,8 +19,11 @@ export class PicklistCreateDialogComponent
 
   selectionListName: String;
 
+  @ViewChild('fail', { static: true }) private fail: AlertDialogComponent;
+
   constructor(
     private idl: IdlService,
+    private evt: EventService,
     private net: NetService,
     private auth: AuthService,
     private modal: NgbModal
@@ -39,8 +44,19 @@ export class PicklistCreateDialogComponent
       'open-ils.acq.picklist.create',
       this.auth.token(), picklist
     ).subscribe(
-      new_id => this.close(new_id),
-      err => throwError(err)
+      (res) => {
+        if (this.evt.parse(res)) {
+          console.error(res);
+          this.fail.open();
+        } else {
+          console.log(res);
+        }
+      },
+      (err) => {
+        console.error(err);
+        this.fail.open();
+      },
+      () => this.close(true)
     );
   }
 }
index cb6f658..e1e3b60 100644 (file)
@@ -1,7 +1,9 @@
 import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
 import {Observable, forkJoin, from, empty, throwError} from 'rxjs';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
@@ -18,8 +20,11 @@ export class PicklistDeleteDialogComponent
   @Input() grid: any;
   listNames: string[];
 
+  @ViewChild('fail', { static: true }) private fail: AlertDialogComponent;
+
   constructor(
     private idl: IdlService,
+    private evt: EventService,
     private net: NetService,
     private auth: AuthService,
     private modal: NgbModal
@@ -50,8 +55,19 @@ export class PicklistDeleteDialogComponent
       observables.push( that.deleteList(r) );
     });
     forkJoin(observables).subscribe(
-      results => this.close(results),
-      err => throwError(err)
+      (res) => {
+        if (this.evt.parse(res)) {
+          console.error(res);
+          this.fail.open();
+        } else {
+          console.log(res);
+        }
+      },
+      (err) => {
+        console.error(err);
+        this.fail.open();
+      },
+      () => this.close(true)
     );
   }
 }
index a347689..d2b6755 100644 (file)
@@ -1,7 +1,9 @@
 import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
 import {Observable, forkJoin, from, empty, throwError} from 'rxjs';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {AlertDialogComponent} from '@eg/share/dialog/alert.component';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
@@ -20,8 +22,11 @@ export class PicklistMergeDialogComponent
   leadList: number;
   selectedLists: IdlObject[];
 
+  @ViewChild('fail', { static: true }) private fail: AlertDialogComponent;
+
   constructor(
     private idl: IdlService,
+    private evt: EventService,
     private net: NetService,
     private auth: AuthService,
     private modal: NgbModal
@@ -45,8 +50,18 @@ export class PicklistMergeDialogComponent
       this.auth.token(), this.leadList,
       this.selectedLists.map( list => list.id() ).filter(function(p) { return p != that.leadList; })
     ).subscribe(
-      (res) => console.log('res',res),
-      (err) => throwError(err),
+      (res) => {
+        if (this.evt.parse(res)) {
+          console.error(res);
+          this.fail.open();
+        } else {
+          console.log(res);
+        }
+      },
+      (err) => {
+        console.error(err);
+        this.fail.open();
+      },
       () => this.close(true)
     );
   }