forked from mystiq/hydrogen-web
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:
parent
c9ee5a5db2
commit
e6a46874c4
1 changed files with 8 additions and 3 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue