Handling stream error events
- Dominant language
- JavaScript
- Stars
- 4.7k
- Forks
- 852
- PR merge metrics
- No merged PRs in 30d
Description
I know that the error `Error: aborted` is thrown when something is wrong with the ytdl's stream, and I think it's caused by youtube's eventual content update (at least it's what I heard), so I tried to handle this error with ytdl's default event handler, but it wasn't enought.
When the error arises, I try to treat it by just retrying the reproduction of the stream, something like:
```ts
import ytdl from 'ytdl-core' // version 4.11.5
const stream = ytdl(url, {
filter: format => format.hasAudio && !format.hasVideo
// I realized that some songs could not contain higher quality audio.
// Additionally, higher audio quality frequently throws more errors like this.
&& (format.audioBitrate === 128 || format.audioSampleRate === '48000' || format.audioSampleRate === '41800' || true)
})
stream.on('error', err => {
console.log('[ SoundboardPlayer Error ] SoundboardPlayer got an Stream Error:\n', String(err))
// Retry to play the song by creating another stream
})
```
It's ok to get this error, but the real problem here is that, instead of treating the error as it was supposed to do, the event handler still throws the error after logging it to the console. The output:
```pwsh
[ SoundboardPlayer Error ] SoundboardPlayer got an Stream Error:
Error: aborted
Error: aborted
at connResetException (node:internal/errors:787:14)
at TLSSocket.socketCloseListener (node:_http_client:455:19)
at TLSSocket.emit (node:events:530:35)
at node:net:337:12
at TCP.done (node:_tls_wrap:657:7)
[ERROR] 20:21:55 Error: aborted
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.