changeset 494:f52eb1b422f5

Display errors to user instead of logging to console.
author Lucas Thompson <dev@lucas.im>
date Thu, 06 Jul 2017 19:48:22 +0100
parents 7f9fb84816b9
children 33b4106af9dd
files src/app/app.component.ts src/app/services/audio-recorder/audio-recorder.service.ts src/app/services/feature-extraction/feature-extraction.service.ts
diffstat 3 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/app.component.ts	Thu Jul 06 19:47:18 2017 +0100
+++ b/src/app/app.component.ts	Thu Jul 06 19:48:22 2017 +0100
@@ -2,7 +2,8 @@
 import {
   AudioPlayerService,
   AudioResourceError,
-  AudioResource
+  AudioResource,
+  AudioLoadResponse
 } from './services/audio-player/audio-player.service';
 import {
   ExtractionResult,
@@ -25,6 +26,7 @@
 import {UrlResourceLifetimeManager} from './app.module';
 import {createExtractionRequest} from './analysis-item/AnalysisItem';
 import {PersistentStack} from './Session';
+import {NotificationService} from './services/notifications/notifications.service';
 
 @Component({
   selector: 'ugly-root',
@@ -46,7 +48,8 @@
               private sanitizer: DomSanitizer,
               @Inject(
                 'UrlResourceLifetimeManager'
-              ) private resourceManager: UrlResourceLifetimeManager) {
+              ) private resourceManager: UrlResourceLifetimeManager,
+              private notifier: NotificationService) {
     this.analyses = new PersistentStack<AnalysisItem>();
     this.canExtract = false;
     this.nRecordings = 0;
@@ -64,8 +67,10 @@
           val => isPendingRootAudioItem(val) && val.uri === getRootAudioItem(
             this.analyses.get(0)
           ).uri;
-        const wasError = (resource as AudioResourceError).message != null;
-        if (wasError) {
+        const wasError = (res: AudioLoadResponse):
+          res is AudioResourceError => (res as any).message != null;
+        if (wasError(resource)) {
+          this.notifier.displayError(resource.message);
           this.analyses.findIndexAndUse(
             findCurrentAudio,
             index => this.analyses.remove(index)
@@ -208,7 +213,7 @@
           val => val.id === analysis.id,
           index => this.analyses.remove(index)
         );
-        console.error(`Error whilst extracting: ${err}`);
+        this.notifier.displayError(`Error whilst extracting: ${err}`);
       });
   }
 }
--- a/src/app/services/audio-recorder/audio-recorder.service.ts	Thu Jul 06 19:47:18 2017 +0100
+++ b/src/app/services/audio-recorder/audio-recorder.service.ts	Thu Jul 06 19:48:22 2017 +0100
@@ -4,6 +4,7 @@
 import {Injectable, Inject, NgZone} from '@angular/core';
 import {Observable} from 'rxjs/Observable';
 import {Subject} from 'rxjs/Subject';
+import {NotificationService} from '../notifications/notifications.service';
 
 
 // seems the TypeScript definitions are not up to date,
@@ -119,7 +120,8 @@
               @Inject(
                 'MediaRecorderFactory'
               ) recorderImpl: MediaRecorderConstructor,
-              private ngZone: NgZone) {
+              private ngZone: NgZone,
+              private notifier: NotificationService) {
     this.requestProvider = requestProvider;
     this.recorderImpl = recorderImpl;
     this.recordingStateChange = new Subject<RecorderServiceStatus>();
@@ -163,7 +165,7 @@
         .then(recorder => this.startRecording(recorder))
         .catch(e => {
           this.recordingStateChange.next('disabled'); // don't really need to do this
-          console.warn(e); // TODO emit an error message for display?
+          this.notifier.displayError(e);
         });
     }
   }
--- a/src/app/services/feature-extraction/feature-extraction.service.ts	Thu Jul 06 19:47:18 2017 +0100
+++ b/src/app/services/feature-extraction/feature-extraction.service.ts	Thu Jul 06 19:48:22 2017 +0100
@@ -18,6 +18,7 @@
   KnownShapedFeature,
   toKnownShape
 } from '../../visualisations/FeatureUtilities';
+import {NotificationService} from '../notifications/notifications.service';
 
 type RepoUri = string;
 export interface AvailableLibraries {
@@ -48,7 +49,8 @@
   private client: WebWorkerStreamingClient;
 
   constructor(private http: Http,
-              @Inject('PiperRepoUri') private repositoryUri: RepoUri) {
+              @Inject('PiperRepoUri') private repositoryUri: RepoUri,
+              private notifier: NotificationService) {
     this.worker = new Worker('bootstrap-feature-extraction-worker.js');
     this.featuresExtracted = new Subject<ExtractionResult>();
     this.featuresExtracted$ = this.featuresExtracted.asObservable();
@@ -117,7 +119,7 @@
           params: res.json()
         });
       })
-      .catch(console.error); // TODO Report error to user
+      .catch(err => this.notifier.displayError(err));
   }
 
   load(libraryKey: string): void {