mirror of https://github.com/waku-org/js-waku.git
Do not fail if a chat message is malformed
This commit is contained in:
parent
bc544c8e0b
commit
8073021d82
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue