From 8073021d820d2ed45f065eeff5bddcb1d6d4a5e6 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 11 Jun 2021 14:33:03 +1000 Subject: [PATCH] Do not fail if a chat message is malformed --- CHANGELOG.md | 1 + examples/web-chat/src/Message.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e0164202..0e316f039b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Test: Upgrade nim-waku node to v0.4. - Waku Light Push upgraded to `2.0.0-beta1`. +- Examples (web chat): Catch error if chat message decoding fails. ## [0.6.0] - 2021-06-09 diff --git a/examples/web-chat/src/Message.ts b/examples/web-chat/src/Message.ts index cb49a14440..2ec9884caf 100644 --- a/examples/web-chat/src/Message.ts +++ b/examples/web-chat/src/Message.ts @@ -12,9 +12,17 @@ export class Message { static fromWakuMessage(wakuMsg: WakuMessage): Message | undefined { if (wakuMsg.payload) { - const chatMsg = ChatMessage.decode(wakuMsg.payload); - if (chatMsg) { - return new Message(chatMsg, wakuMsg.timestamp); + try { + const chatMsg = ChatMessage.decode(wakuMsg.payload); + if (chatMsg) { + return new Message(chatMsg, wakuMsg.timestamp); + } + } catch (e) { + console.error( + 'Failed to decode chat message', + wakuMsg.payloadAsUtf8, + e + ); } } return;