aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/Errors.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-04-23 15:18:46 +0000
committerMaximilian Krambach <[email protected]>2018-04-23 15:18:46 +0000
commitd62f66b1fb47f2075770d896f672748a4136e70b (patch)
tree57cd622c1bfa8e3b9c22ef5a21b14915c3223c65 /lang/js/src/Errors.js
parentjs: encrypt improvement and decrypt method (diff)
downloadgpgme-d62f66b1fb47f2075770d896f672748a4136e70b.tar.gz
gpgme-d62f66b1fb47f2075770d896f672748a4136e70b.zip
js: Key handling stubs, Error handling, refactoring
-- * Error handling: introduced GPGMEJS_Error class that handles errors at a more centralized and consistent position * src/Connection.js: The nativeMessaging port now opens per session instead of per message. Some methods were added that reflect this change - added methods disconnect() and reconnect() - added connection status query * src/gpgmejs.js - stub for key deletion - error handling - high level API for changing connection status * src/gpgmejs_openpgpjs.js - added stubs for Key/Keyring handling according to current state of discussion. It is still subject to change * src/Helpers.js - toKeyIdArray creates an array of KeyIds, now accepting fingerprints, GPGMEJS_Key objects and openpgp Key objects. * Key objects (src/Key.js) Querying information about a key directly from gnupg. Currently a stub, only the Key.fingerprint is functional. * Keyring queries (src/Keyring.js): Listing and searching keys. Currently a stub.
Diffstat (limited to '')
-rw-r--r--lang/js/src/Errors.js148
1 files changed, 148 insertions, 0 deletions
diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js
new file mode 100644
index 00000000..c2356f7c
--- /dev/null
+++ b/lang/js/src/Errors.js
@@ -0,0 +1,148 @@
+/* gpgme.js - Javascript integration for gpgme
+ * Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GPGME is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+// This is a preliminary collection of erors and warnings to be thrown and implemented.
+
+// general idea: if throw , throw the NAME
+// return false || 'return' property
+
+//TODO: Connection.NOCONNECT promise
+//connection.timeout: Be aware of pinentry
+
+export class GPGMEJS_Error {
+
+ constructor(code = 'GENERIC_ERROR', details){
+ let config = { //TODO TEMP
+ debug: 'console', // |'alert'
+ throw: 'default' // | 'always' | 'never'
+ };
+ let errors = { //TODO: someplace else
+ //Connection errors
+ 'ALREADY_CONNECTED':{
+ msg: 'The connection was already established. The action would overwrite the context',
+ throw: true
+ },
+ 'NO_CONNECT': {
+ msg:'Connection with the nativeMessaging host could not be established.',
+ throw: true
+ },
+ 'EMPTY_GPG_ANSWER':{
+ msg: 'The nativeMesaging answer was empty',
+ throw: true
+ },
+ 'TIMEOUT': {
+ msg: 'A timeout was exceeded.',
+ throw: false
+ },
+
+ 'UNEXPECTED_ANSWER': {
+ msg: 'The answer from gnupg was not as expected',
+ throw: true
+ },
+
+ // Message/Data Errors
+
+ 'NO_KEYS' : {
+ msg: 'There were no valid keys provided.',
+ throw: true
+ },
+ 'NOT_A_FPR': {
+ msg: 'The String is not an accepted fingerprint',
+ throw: false
+ },
+ 'MSG_INCOMPLETE': {
+ msg: 'The Message did not match the minimum requirements for the interaction',
+ throw: true
+ },
+ 'EMPTY_MSG' : {
+ msg: 'The Message has no data.',
+ throw: true
+ },
+ 'MSG_NODATA':{
+ msg: 'The data sent is empty. This may be unintentional.',
+ throw: false
+ },
+ 'MSG_OP_PENDING': {
+ msg: 'There is no operation specified yet. The parameter cannot be set',
+ throw: false
+ },
+ 'WRONG_OP': {
+ msg: "The operation requested could not be found",
+ throw: true
+ },
+
+ //generic errors
+
+ 'WRONGPARAM':{
+ msg: 'invalid parameter was found',
+ throw: true
+ },
+ 'WRONGTYPE':{
+ msg: 'invalid parameter type was found',
+ throw: true
+ },
+ 'NOT_IMPLEMENTED': {
+ msg: 'A openpgpjs parameter was submitted that is not implemented',
+ throw: true
+ },
+ 'GENERIC_ERROR': {
+ msg: 'Unspecified error',
+ throw: true
+ },
+
+ // hopefully temporary errors
+
+ 'NOT_YET_IMPLEMENTED': {
+ msg: 'Support of this is probable, but it is not implemented yet',
+ throw: false
+ }
+ }
+ if (!errors.hasOwnProperty(code)){
+ throw('GENERIC_ERROR');
+ }
+ let msg = code;
+ if (errors[code].msg !== undefined){
+ msg = msg + ': ' + errors[code].msg;
+ }
+ if (details){
+ msg = msg + ' ' + details;
+ }
+ if (config.debug === 'console'){
+ console.log(msg);
+ } else if (config.debug === 'alert'){
+ alert(msg);
+ }
+ switch (config.throw) {
+ case 'default':
+ if (errors[code].throw === true){
+ throw(code);
+ }
+ break;
+ case 'always':
+ throw(code);
+ break;
+
+ case 'never':
+ break;
+ default:
+ throw('GENERIC_ERROR');
+ }
+ }
+}