From 29afcce55560eb524fd79350a462cd0189a949ef Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Mon, 8 May 2023 17:40:35 +0200 Subject: [PATCH] fix(editor): catch error when refreshing note metadata Signed-off-by: Tilman Vatteroth --- .../hooks/yjs/use-on-metadata-updated.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-on-metadata-updated.ts b/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-on-metadata-updated.ts index 23540a83f..b67b874bc 100644 --- a/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-on-metadata-updated.ts +++ b/frontend/src/components/editor-page/editor-pane/hooks/yjs/use-on-metadata-updated.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ import { updateMetadata } from '../../../../../redux/note-details/methods' +import { useUiNotifications } from '../../../../notifications/ui-notification-boundary' import type { MessageTransporter } from '@hedgedoc/commons' import { MessageType } from '@hedgedoc/commons' import type { Listener } from 'eventemitter2' @@ -15,12 +16,20 @@ import { useEffect } from 'react' * @param websocketConnection The websocket connection that emits the metadata changed event */ export const useOnMetadataUpdated = (websocketConnection: MessageTransporter): void => { + const { showErrorNotification } = useUiNotifications() + useEffect(() => { - const listener = websocketConnection.on(MessageType.METADATA_UPDATED, () => void updateMetadata(), { - objectify: true - }) as Listener + const listener = websocketConnection.on( + MessageType.METADATA_UPDATED, + () => { + updateMetadata().catch(showErrorNotification('common.errorWhileLoading', { name: 'note metadata refresh' })) + }, + { + objectify: true + } + ) as Listener return () => { listener.off() } - }, [websocketConnection]) + }, [showErrorNotification, websocketConnection]) }