From f5e27a12d3fd22b95e83c03a5650659bfa2299b9 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 19 Jun 2019 12:57:20 +0200 Subject: js: Error handling for browser errors -- * Connection.js - Add some meaningful nativeMessaging feedback for failing communication due to misconfiguration or other browser-originated fails - add an "isDisconnected" property - "isNativeHostUnknown" tries to match browser's feedback string if the browser does not find gpgme-json * init.js - initialization will now reject with a more meaningful error if the configuration is not set up or other browser-based errors (chrome.runtime.lastError) are present. This should speed up the normal initialization (not having to waiting for a timeout any more in case of improper setup) * errors.js - CONN_NATIVEMESSAGE: New error that passes the browser's nativeMessaging error - CONN_NO_CONFIG: native messaging error indicating that the nativeMessaging host was not set up properly * unittests.js: - added the "isDisconnected" property to the startup tests - added tests for proper behavior of connection checks --- lang/js/src/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lang/js/src/index.js') diff --git a/lang/js/src/index.js b/lang/js/src/index.js index 106086fb..3c31a047 100644 --- a/lang/js/src/index.js +++ b/lang/js/src/index.js @@ -33,7 +33,7 @@ import { Connection } from './Connection'; * An unsuccessful attempt will reject as a GPGME_Error. * @param {Object} config (optional) configuration options * @param {Number} config.timeout set the timeout for the initial connection - * check. On some machines and operating systems a default timeout of 500 ms is + * check. On some machines and operating systems a default timeout of 1000 ms is * too low, so a higher number might be attempted. * @returns {Promise} * @async @@ -46,7 +46,17 @@ function init ({ timeout = 1000 } = {}){ if (result === true) { resolve(new GpgME()); } else { - reject(gpgme_error('CONN_NO_CONNECT')); + if (connection._connectionError) { + if (connection.isNativeHostUnknown){ + reject(gpgme_error('CONN_NO_CONFIG')); + } else { + reject(gpgme_error('CONN_NATIVEMESSAGE', + connection._connectionError) + ); + } + } else { + reject(gpgme_error('CONN_TIMEOUT')); + } } }, function (){ // unspecific connection error. Should not happen reject(gpgme_error('CONN_NO_CONNECT')); -- cgit v1.2.3