Wrap decoding in try...catch (#279)

This commit is contained in:
Felicio Mununga 2022-06-17 09:35:40 +02:00 committed by GitHub
parent 9010b1d585
commit fb78bc5dc8
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 104 additions and 97 deletions

View File

@ -41,7 +41,9 @@ export function handleWakuMessage(
if (decodedProtocol) {
messageToDecode = decodedProtocol.publicMessage
}
} catch {}
} catch {
// eslint-disable-next-line no-empty
}
const decodedMetadata = ApplicationMetadataMessage.decode(messageToDecode)
if (!decodedMetadata.payload) {
@ -67,6 +69,7 @@ export function handleWakuMessage(
let success = false
// decode, map and handle (events)
try {
switch (decodedMetadata.type) {
case ApplicationMetadataMessage.Type.TYPE_COMMUNITY_DESCRIPTION: {
// decode
@ -168,6 +171,10 @@ export function handleWakuMessage(
break
}
} catch {
// protons-runtime throws when trying to decode invalid protocol buffers
success = true
}
if (success) {
client.wakuMessages.add(messageId)