Mercurial > hg > ugly-duckling
comparison src/app/app.component.ts @ 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 | c9f12a9c1d5c |
children | c39df81c4dae |
comparison
equal
deleted
inserted
replaced
493:7f9fb84816b9 | 494:f52eb1b422f5 |
---|---|
1 import {Component, Inject, OnDestroy} from '@angular/core'; | 1 import {Component, Inject, OnDestroy} from '@angular/core'; |
2 import { | 2 import { |
3 AudioPlayerService, | 3 AudioPlayerService, |
4 AudioResourceError, | 4 AudioResourceError, |
5 AudioResource | 5 AudioResource, |
6 AudioLoadResponse | |
6 } from './services/audio-player/audio-player.service'; | 7 } from './services/audio-player/audio-player.service'; |
7 import { | 8 import { |
8 ExtractionResult, | 9 ExtractionResult, |
9 FeatureExtractionService | 10 FeatureExtractionService |
10 } from './services/feature-extraction/feature-extraction.service'; | 11 } from './services/feature-extraction/feature-extraction.service'; |
23 } from './analysis-item/AnalysisItem'; | 24 } from './analysis-item/AnalysisItem'; |
24 import {OnSeekHandler} from './playhead/PlayHeadHelpers'; | 25 import {OnSeekHandler} from './playhead/PlayHeadHelpers'; |
25 import {UrlResourceLifetimeManager} from './app.module'; | 26 import {UrlResourceLifetimeManager} from './app.module'; |
26 import {createExtractionRequest} from './analysis-item/AnalysisItem'; | 27 import {createExtractionRequest} from './analysis-item/AnalysisItem'; |
27 import {PersistentStack} from './Session'; | 28 import {PersistentStack} from './Session'; |
29 import {NotificationService} from './services/notifications/notifications.service'; | |
28 | 30 |
29 @Component({ | 31 @Component({ |
30 selector: 'ugly-root', | 32 selector: 'ugly-root', |
31 templateUrl: './app.component.html', | 33 templateUrl: './app.component.html', |
32 styleUrls: ['./app.component.css'] | 34 styleUrls: ['./app.component.css'] |
44 private featureService: FeatureExtractionService, | 46 private featureService: FeatureExtractionService, |
45 private iconRegistry: MdIconRegistry, | 47 private iconRegistry: MdIconRegistry, |
46 private sanitizer: DomSanitizer, | 48 private sanitizer: DomSanitizer, |
47 @Inject( | 49 @Inject( |
48 'UrlResourceLifetimeManager' | 50 'UrlResourceLifetimeManager' |
49 ) private resourceManager: UrlResourceLifetimeManager) { | 51 ) private resourceManager: UrlResourceLifetimeManager, |
52 private notifier: NotificationService) { | |
50 this.analyses = new PersistentStack<AnalysisItem>(); | 53 this.analyses = new PersistentStack<AnalysisItem>(); |
51 this.canExtract = false; | 54 this.canExtract = false; |
52 this.nRecordings = 0; | 55 this.nRecordings = 0; |
53 this.countingId = 0; | 56 this.countingId = 0; |
54 this.onSeek = (time) => this.audioService.seekTo(time); | 57 this.onSeek = (time) => this.audioService.seekTo(time); |
62 resource => { | 65 resource => { |
63 const findCurrentAudio = | 66 const findCurrentAudio = |
64 val => isPendingRootAudioItem(val) && val.uri === getRootAudioItem( | 67 val => isPendingRootAudioItem(val) && val.uri === getRootAudioItem( |
65 this.analyses.get(0) | 68 this.analyses.get(0) |
66 ).uri; | 69 ).uri; |
67 const wasError = (resource as AudioResourceError).message != null; | 70 const wasError = (res: AudioLoadResponse): |
68 if (wasError) { | 71 res is AudioResourceError => (res as any).message != null; |
72 if (wasError(resource)) { | |
73 this.notifier.displayError(resource.message); | |
69 this.analyses.findIndexAndUse( | 74 this.analyses.findIndexAndUse( |
70 findCurrentAudio, | 75 findCurrentAudio, |
71 index => this.analyses.remove(index) | 76 index => this.analyses.remove(index) |
72 ); | 77 ); |
73 this.canExtract = false; | 78 this.canExtract = false; |
206 this.canExtract = true; | 211 this.canExtract = true; |
207 this.analyses.findIndexAndUse( | 212 this.analyses.findIndexAndUse( |
208 val => val.id === analysis.id, | 213 val => val.id === analysis.id, |
209 index => this.analyses.remove(index) | 214 index => this.analyses.remove(index) |
210 ); | 215 ); |
211 console.error(`Error whilst extracting: ${err}`); | 216 this.notifier.displayError(`Error whilst extracting: ${err}`); |
212 }); | 217 }); |
213 } | 218 } |
214 } | 219 } |