aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/Helpers.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-04-25 08:54:24 +0000
committerMaximilian Krambach <[email protected]>2018-04-25 08:54:24 +0000
commitc72adc00965fe4fcedd9d18609211021a091b28b (patch)
treeaf1cc5df7da410f42f2762da9b03b5ca3d39087d /lang/js/src/Helpers.js
parentjs: allow openpgp-like Message objects as Data (diff)
downloadgpgme-c72adc00965fe4fcedd9d18609211021a091b28b.tar.gz
gpgme-c72adc00965fe4fcedd9d18609211021a091b28b.zip
js: change in Error behaviour
-- * Error objects will now return the error code if defined as error type in src/Errors.js, or do a console.log if it is a warning. Errors from the native gpgme-json will be marked as GNUPG_ERROR.
Diffstat (limited to 'lang/js/src/Helpers.js')
-rw-r--r--lang/js/src/Helpers.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/lang/js/src/Helpers.js b/lang/js/src/Helpers.js
index 922ca06c..d9750ba7 100644
--- a/lang/js/src/Helpers.js
+++ b/lang/js/src/Helpers.js
@@ -1,5 +1,3 @@
-import { GPGMEJS_Error } from "./Errors";
-
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
@@ -19,18 +17,19 @@ import { GPGMEJS_Error } from "./Errors";
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
* SPDX-License-Identifier: LGPL-2.1+
*/
+import { GPGMEJS_Error } from "./Errors";
/**
* Tries to return an array of fingerprints, either from input fingerprints or
* from Key objects
* @param {Key |Array<Key>| GPGME_Key | Array<GPGME_Key>|String|Array<String>} input
- * @param {Boolean} nocheck if set, an empty result is acceptable
* @returns {Array<String>} Array of fingerprints.
*/
export function toKeyIdArray(input, nocheck){
if (!input){
- return (nocheck ===true)? [] : new GPGMEJS_Error('NO_KEYS');
+ GPGMEJS_Error('MSG_NO_KEYS');
+ return [];
}
if (!Array.isArray(input)){
input = [input];
@@ -41,7 +40,7 @@ export function toKeyIdArray(input, nocheck){
if (isFingerprint(input[i]) === true){
result.push(input[i]);
} else {
- GPGMEJS_Error
+ GPGMEJS_Error('MSG_NOT_A_FPR');
}
} else if (typeof(input[i]) === 'object'){
let fpr = '';
@@ -53,13 +52,16 @@ export function toKeyIdArray(input, nocheck){
}
if (isFingerprint(fpr) === true){
result.push(fpr);
+ } else {
+ GPGMEJS_Error('MSG_NOT_A_FPR');
}
} else {
- return new GPGMEJS_Error('WRONGTYPE');
+ return GPGMEJS_Error('PARAM_WRONG');
}
}
if (result.length === 0){
- return (nocheck===true)? [] : new GPGMEJS_Error('NO_KEYS');
+ GPGMEJS_Error('MSG_NO_KEYS');
+ return [];
} else {
return result;
}