Browse Source

silence timeout errors

Olivier Massot 2 years ago
parent
commit
bc5db2e699
1 changed files with 5 additions and 2 deletions
  1. 5 2
      services/sse/sseSource.ts

+ 5 - 2
services/sse/sseSource.ts

@@ -7,7 +7,6 @@ class SseSource {
   protected readonly onClose: (() => void)
   protected readonly withCredentials: boolean
   protected eventSource: EventSourcePolyfill | null = null
-
   constructor(
     mercureHubBaseUrl: string,
     topic: string,
@@ -49,7 +48,11 @@ class SseSource {
     this.eventSource = this.createEventSource(this.url.toString(), this.withCredentials)
 
     this.eventSource.onerror = (event) => {
-      console.error('SSE - An error happened')
+      if (event.target.readyState === EventSource.CLOSED) {
+        console.log("SSE closed (" + event.target.readyState + ")");
+      }
+      // @ts-ignore
+      this.eventSource.close();
     }
     this.eventSource.onopen = () => {
       console.log('SSE - Listening for events...')