Added database connection error handling

This commit is contained in:
Geomitron
2020-05-27 15:07:31 -04:00
parent 157ed0c27a
commit 323a9116e3
6 changed files with 40 additions and 14 deletions

View File

@@ -21,7 +21,12 @@ export class SearchService {
if (this.awaitingResults) { return }
this.awaitingResults = true
this.currentQuery = { query, type: SearchType.Any, offset: 0, length: 50 + 1 } // TODO: make length a setting
this.results = this.trimLastChart(await this.electronService.invoke('song-search', this.currentQuery))
try {
this.results = this.trimLastChart(await this.electronService.invoke('song-search', this.currentQuery))
} catch (err) {
this.results = []
this.resultsChangedEmitter.error(undefined)
}
this.awaitingResults = false
this.resultsChangedEmitter.emit(this.results)
@@ -49,6 +54,14 @@ export class SearchService {
this.newResultsEmitter.subscribe(callback)
}
/**
* Event emitted when a search fails.
* (emitted before `onSearchChanged`)
*/
onSearchError(callback: () => void) {
this.resultsChangedEmitter.subscribe(() => { /** Do nothing */ }, callback)
}
get resultCount() {
return this.results.length
}