Skip to content

Commit

Permalink
rethrow exceptions rather than creating new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Butler committed Dec 22, 2017
1 parent a2e0ccf commit b4eb825
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions build/pmcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function decryptPrivateKey(privKey, privKeyPassCode) {
return keys[0];
}

return Promise.reject(new Error('Private key decryption failed')); // Do NOT make this an Error object
return Promise.reject(new Error('Private key decryption failed'));
});
}

Expand All @@ -200,12 +200,12 @@ function decryptSessionKey(options) {

return result;
}).catch(function (err) {
console.log(err);
return Promise.reject(new Error('Session key decryption failed'));
console.error(err);
return Promise.reject(err);
});
} catch (err) {
if (err.message === 'CFB decrypt: invalid key' && options.passwords && options.passwords.length) {
return Promise.reject(new Error('Incorrect message password')); // Bad password, reject without Error object
return Promise.reject(new Error('Incorrect message password'));
}
return Promise.reject(err);
}
Expand Down Expand Up @@ -532,8 +532,8 @@ function decryptMessage(options) {

return { data: data, filename: filename, verified: verified, signatures: signatures };
}).catch(function (err) {
console.log(err);
return Promise.reject(new Error('Decryption failed'));
console.error(err);
return Promise.reject(err);
});
} catch (err) {
if (err.message === 'CFB decrypt: invalid key' && options.passwords && options.passwords.length) {
Expand Down Expand Up @@ -621,7 +621,7 @@ function encryptMessage(options) {
module.exports = encryptMessage;

},{}],11:[function(require,module,exports){
'use strict';
"use strict";

function getMessage(message) {

Expand Down Expand Up @@ -666,8 +666,8 @@ function createMessage(source) {
function signMessage(options) {

return openpgp.sign(options).catch(function (err) {
console.log(err);
return Promise.reject(new Error('Message signing failed'));
console.error(err);
return Promise.reject(err);
});
}

Expand All @@ -692,8 +692,8 @@ function verifyMessage(options) {
}
return { data: data, verified: verified, signatures: signatures };
}).catch(function (err) {
console.log(err);
return Promise.reject(new Error('Message verification failed'));
console.error(err);
return Promise.reject(err);
});
}

Expand Down
8 changes: 4 additions & 4 deletions lib/key/decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function decryptPrivateKey(privKey, privKeyPassCode) {
return keys[0];
}

return Promise.reject(new Error('Private key decryption failed')); // Do NOT make this an Error object
return Promise.reject(new Error('Private key decryption failed'));
});
}

Expand All @@ -41,12 +41,12 @@ function decryptSessionKey(options) {
return result;
})
.catch((err) => {
console.log(err);
return Promise.reject(new Error('Session key decryption failed'));
console.error(err);
return Promise.reject(err);
});
} catch (err) {
if (err.message === 'CFB decrypt: invalid key' && options.passwords && options.passwords.length) {
return Promise.reject(new Error('Incorrect message password')); // Bad password, reject without Error object
return Promise.reject(new Error('Incorrect message password'));
}
return Promise.reject(err);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/message/decrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function decryptMessage(options) {
return { data, filename, verified, signatures };
})
.catch((err) => {
console.log(err);
return Promise.reject(new Error('Decryption failed'));
console.error(err);
return Promise.reject(err);
});
} catch (err) {
if (err.message === 'CFB decrypt: invalid key' && options.passwords && options.passwords.length) {
Expand Down
8 changes: 4 additions & 4 deletions lib/message/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function signMessage(options) {

return openpgp.sign(options)
.catch((err) => {
console.log(err);
return Promise.reject(new Error('Message signing failed'));
console.error(err);
return Promise.reject(err);
});
}

Expand All @@ -67,8 +67,8 @@ function verifyMessage(options) {
return {data, verified, signatures};
})
.catch(function(err) {
console.log(err);
return Promise.reject(new Error('Message verification failed'));
console.error(err);
return Promise.reject(err);
});
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pmcrypto",
"version": "2.0.4",
"version": "2.0.5",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"btoa": "*",
"atob": "*",
"es6-promise": "*",
"openpgp": "2.5.12"
"openpgp": "2.6.1"
},
"devDependencies": {
"babel-plugin-istanbul": "^4.1.4",
Expand Down

0 comments on commit b4eb825

Please sign in to comment.