wrap olm error for creating session in DecryptionError

so we can relate it back to the event that caused it
This commit is contained in:
Bruno Windels 2020-09-21 17:58:13 +02:00
parent c9ee5a5db2
commit e6a46874c4

View File

@ -115,7 +115,12 @@ export class Decryption {
} }
// could not decrypt with any existing session // could not decrypt with any existing session
if (typeof plaintext !== "string" && isPreKeyMessage(message)) { if (typeof plaintext !== "string" && isPreKeyMessage(message)) {
const createResult = this._createSessionAndDecrypt(senderKey, message, timestamp); let createResult;
try {
createResult = this._createSessionAndDecrypt(senderKey, message, timestamp);
} catch (error) {
throw new DecryptionError(`Could not create inbound olm session: ${error.message}`, event, {senderKey, error});
}
senderKeyDecryption.addNewSession(createResult.session); senderKeyDecryption.addNewSession(createResult.session);
plaintext = createResult.plaintext; plaintext = createResult.plaintext;
} }
@ -123,8 +128,8 @@ export class Decryption {
let payload; let payload;
try { try {
payload = JSON.parse(plaintext); payload = JSON.parse(plaintext);
} catch (err) { } catch (error) {
throw new DecryptionError("PLAINTEXT_NOT_JSON", event, {plaintext, err}); throw new DecryptionError("PLAINTEXT_NOT_JSON", event, {plaintext, error});
} }
this._validatePayload(payload, event); this._validatePayload(payload, event);
return new DecryptionResult(payload, senderKey, payload.keys); return new DecryptionResult(payload, senderKey, payload.keys);