Do not fail if a chat message is malformed

This commit is contained in:
Franck Royer 2021-06-11 14:33:03 +10:00
parent bc544c8e0b
commit 8073021d82
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 12 additions and 3 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Test: Upgrade nim-waku node to v0.4. - Test: Upgrade nim-waku node to v0.4.
- Waku Light Push upgraded to `2.0.0-beta1`. - 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 ## [0.6.0] - 2021-06-09

View File

@ -12,10 +12,18 @@ export class Message {
static fromWakuMessage(wakuMsg: WakuMessage): Message | undefined { static fromWakuMessage(wakuMsg: WakuMessage): Message | undefined {
if (wakuMsg.payload) { if (wakuMsg.payload) {
try {
const chatMsg = ChatMessage.decode(wakuMsg.payload); const chatMsg = ChatMessage.decode(wakuMsg.payload);
if (chatMsg) { if (chatMsg) {
return new Message(chatMsg, wakuMsg.timestamp); return new Message(chatMsg, wakuMsg.timestamp);
} }
} catch (e) {
console.error(
'Failed to decode chat message',
wakuMsg.payloadAsUtf8,
e
);
}
} }
return; return;
} }