Better webtorrent error handling
This commit is contained in:
parent
407c4473ad
commit
0c31c33dcb
|
@ -81,10 +81,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
self.player = this
|
self.player = this
|
||||||
})
|
})
|
||||||
|
|
||||||
this.errorsSub = this.webTorrentService.errors.subscribe(err => {
|
this.errorsSub = this.webTorrentService.errors.subscribe(err => this.handleError(err))
|
||||||
const message = typeof err === 'string' ? err : err.message
|
|
||||||
this.notificationsService.error('Error', message)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy () {
|
ngOnDestroy () {
|
||||||
|
@ -117,7 +114,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
// So we create a timer to inform the user the load is abnormally long
|
// So we create a timer to inform the user the load is abnormally long
|
||||||
this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG)
|
this.errorTimer = window.setTimeout(() => this.loadTooLong(), VideoWatchComponent.LOADTIME_TOO_LONG)
|
||||||
|
|
||||||
this.webTorrentService.add(this.video.magnetUri, torrent => {
|
const torrent = this.webTorrentService.add(this.video.magnetUri, torrent => {
|
||||||
// Clear the error timer
|
// Clear the error timer
|
||||||
window.clearTimeout(this.errorTimer)
|
window.clearTimeout(this.errorTimer)
|
||||||
// Maybe the error was fired by the timer, so reset it
|
// Maybe the error was fired by the timer, so reset it
|
||||||
|
@ -143,6 +140,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
this.runInProgress(torrent)
|
this.runInProgress(torrent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
torrent.on('error', err => this.handleError(err))
|
||||||
|
torrent.on('warning', err => this.handleError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
setLike () {
|
setLike () {
|
||||||
|
@ -250,6 +250,19 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
||||||
return this.video.isBlackistableBy(this.authService.getUser())
|
return this.video.isBlackistableBy(this.authService.getUser())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleError (err: any) {
|
||||||
|
const errorMessage: string = typeof err === 'string' ? err : err.message
|
||||||
|
let message = ''
|
||||||
|
|
||||||
|
if (errorMessage.indexOf('http error') !== -1) {
|
||||||
|
message = 'Cannot fetch video from server, maybe down.'
|
||||||
|
} else {
|
||||||
|
message = errorMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
this.notificationsService.error('Error', message)
|
||||||
|
}
|
||||||
|
|
||||||
private checkUserRating () {
|
private checkUserRating () {
|
||||||
// Unlogged users do not have ratings
|
// Unlogged users do not have ratings
|
||||||
if (this.isUserLoggedIn() === false) return
|
if (this.isUserLoggedIn() === false) return
|
||||||
|
|
Loading…
Reference in New Issue