files/en-us/web/api/eventsource/error_event/index.md
{{APIRef("Server Sent Events")}}{{AvailableInWorkers}}
The error event of the {{domxref("EventSource")}} API is fired when a connection with an event source fails to be opened.
This event is not cancelable and does not bubble.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("error", (event) => { })
onerror = (event) => { }
A generic {{domxref("Event")}}.
const evtSource = new EventSource("sse.php");
// addEventListener version
evtSource.addEventListener("error", (e) => {
console.log("An error occurred while attempting to connect.");
});
// onerror version
evtSource.onerror = (e) => {
console.log("An error occurred while attempting to connect.");
};
{{Specifications}}
{{Compat}}