diff --git a/src/routes/_actions/stream/processMessage.js b/src/routes/_actions/stream/processMessage.js index 4a59e571..0368242b 100644 --- a/src/routes/_actions/stream/processMessage.js +++ b/src/routes/_actions/stream/processMessage.js @@ -5,9 +5,9 @@ import { addStatusOrNotification } from '../addStatusOrNotification' const KNOWN_EVENTS = ['update', 'delete', 'notification', 'conversation'] export function processMessage (instanceName, timelineName, message) { - let { event, payload } = message + let { event, payload } = (message || {}) if (!KNOWN_EVENTS.includes(event)) { - console.error("don't know how to handle event", message) + console.warn('ignoring message from server', message) return } mark('processMessage') diff --git a/src/routes/_api/stream/TimelineStream.js b/src/routes/_api/stream/TimelineStream.js index a6cb158c..80d1f74d 100644 --- a/src/routes/_api/stream/TimelineStream.js +++ b/src/routes/_api/stream/TimelineStream.js @@ -3,6 +3,7 @@ import { lifecycle } from '../../_utils/lifecycle' import { getStreamUrl } from './getStreamUrl' import { EventEmitter } from 'events-light' import { eventBus } from '../../_utils/eventBus' +import { safeParse } from '../../_utils/safeParse' export class TimelineStream extends EventEmitter { constructor (streamingApi, accessToken, timeline) { @@ -54,7 +55,7 @@ export class TimelineStream extends EventEmitter { this.emit('reconnect') } } - ws.onmessage = (e) => this.emit('message', JSON.parse(e.data)) + ws.onmessage = (e) => this.emit('message', safeParse(e.data)) ws.onclose = () => this.emit('close') // The ws "onreconnect" event seems unreliable. When the server goes down and comes back up, // it doesn't fire (but "open" does). When we freeze and unfreeze, it fires along with the diff --git a/src/routes/_store/LocalStorageStore.js b/src/routes/_store/LocalStorageStore.js index d5644b61..3eed3403 100644 --- a/src/routes/_store/LocalStorageStore.js +++ b/src/routes/_store/LocalStorageStore.js @@ -1,7 +1,7 @@ import { Store } from 'svelte/store' import { safeLocalStorage as LS } from '../_utils/safeLocalStorage' import { lifecycle } from '../_utils/lifecycle' -import { safeParse } from './safeParse' +import { safeParse } from '../_utils/safeParse' export class LocalStorageStore extends Store { constructor (state, keysToWatch) { diff --git a/src/routes/_store/storeLite.js b/src/routes/_store/storeLite.js index 3f9cee94..cb3c223c 100644 --- a/src/routes/_store/storeLite.js +++ b/src/routes/_store/storeLite.js @@ -1,6 +1,6 @@ // "lite" version of the store used in the inline script. -import { safeParse } from './safeParse' +import { safeParse } from '../_utils/safeParse' import { testHasLocalStorage } from '../_utils/testStorage' const hasLocalStorage = testHasLocalStorage() diff --git a/src/routes/_store/safeParse.js b/src/routes/_utils/safeParse.js similarity index 100% rename from src/routes/_store/safeParse.js rename to src/routes/_utils/safeParse.js