RTCErrorEvent: error property
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The read-onlyRTCErrorEvent propertyerrorcontains anRTCError object describing the details of the error which theevent is announcing.
In this article
Value
AnRTCError object whose properties provide details about the errorwhich has occurred in the context of aWebRTC operation.
Examples
In this example, a handler is established for anRTCDataChannel'serror event.
dataChannel.addEventListener("error", (event) => { let error = event.error; if (error.errorDetail === "sdp-syntax-error") { let errLine = error.sdpLineNumber; let errMessage = error.message; let alertMessage = `A syntax error occurred interpreting line ${errLine} of the SDP: ${errMessage}`; showMyAlertMessage("Data Channel Error", alertMessage); } else { terminateMyConnection(); }});If the error is an SDP syntax error—indicated by itserrorDetailproperty beingsdp-syntax-error—, a message string isconstructed to present the error message and the line number within the SDP at which theerror occurred. This message is then displayed using a function calledshowMyAlertMessage(), which stands in for whatever output mechanism thiscode might use.
Any other error is treated as terminal, causing aterminateMyConnection()function to be called.
The above example usesaddEventListener()to add the handler forerror events. You can also use theRTCDataChannel object'sonerror event handler property, like this:
dataChannel.onerror = (event) => { let error = event.error; /* and so forth */};Specifications
| Specification |
|---|
| WebRTC: Real-Time Communication in Browsers> # dom-rtcerrorevent-error> |