From b83f13cde27c9672ed7c76a117de608203a6b5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obernd=C3=B6rfer?= Date: Tue, 12 Mar 2019 10:45:06 +0100 Subject: [PATCH] Error handling when encrypting the verification email fails --- src/email/email.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/email/email.js b/src/email/email.js index 13d2dbf..9ce90fc 100644 --- a/src/email/email.js +++ b/src/email/email.js @@ -82,19 +82,24 @@ class Email { * @return {string} the encrypted PGP message block */ async _pgpEncrypt(plaintext, publicKeyArmored) { - const {keys : [key], err} = await openpgp.key.readArmored(publicKeyArmored); + const {keys: [key], err} = await openpgp.key.readArmored(publicKeyArmored); if (err) { log.error('email', 'Reading armored key failed.', err, publicKeyArmored); } const now = new Date(); // set message creation date if key has been created with future creation date const msgCreationDate = key.primaryKey.created > now ? key.primaryKey.created : now; - const ciphertext = await openpgp.encrypt({ - message: openpgp.message.fromText(plaintext), - publicKeys: key, - date: msgCreationDate - }); - return ciphertext.data; + try { + const ciphertext = await openpgp.encrypt({ + message: openpgp.message.fromText(plaintext), + publicKeys: key, + date: msgCreationDate + }); + return ciphertext.data; + } catch (error) { + log.error('email', 'Encrypting message failed.', error, publicKeyArmored); + util.throw(400, 'Encrypting message for verification email failed.', error); + } } /**