give better error when olm plaintext is not json

This commit is contained in:
Bruno Windels 2020-09-03 15:28:49 +02:00
parent 1f8005cdfd
commit b2fffee037

View file

@ -111,7 +111,12 @@ export class Decryption {
plaintext = createResult.plaintext;
}
if (typeof plaintext === "string") {
const payload = JSON.parse(plaintext);
let payload;
try {
payload = JSON.parse(plaintext);
} catch (err) {
throw new DecryptionError("Could not JSON decode plaintext", event, {plaintext, err});
}
this._validatePayload(payload, event);
return {event: payload, senderKey};
} else {