Skip to content

Commit cb2ec7c

Browse files
committed
Better DataChannel error handling
Don't emit an RTCErrorEvent since that's not an Error. Instead, emit the actual RTCError, if it exists. Otherwise, make a new Error and emit that.
1 parent 4ddb7d7 commit cb2ec7c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,10 @@ class Peer extends stream.Duplex {
528528
this._channel.onclose = () => {
529529
this._onChannelClose()
530530
}
531-
this._channel.onerror = err => {
531+
this._channel.onerror = event => {
532+
const err = event.error instanceof Error
533+
? event.error
534+
: new Error(`Datachannel error: ${event.message} ${event.filename}:${event.lineno}:${event.colno}`)
532535
this.destroy(errCode(err, 'ERR_DATA_CHANNEL'))
533536
}
534537

0 commit comments

Comments
 (0)