js: reactivate timeout on connection

--
* A timeout of 5 seconds is activated for functions that do not require
  a pinentry. This definition is written to src/permittedOperations.js
* testapplication.js now alerts the proper error codes and messages.
* src/Errors.js fixed two typos in error handling
This commit is contained in:
Maximilian Krambach 2018-04-25 11:32:21 +02:00
parent c72adc0096
commit 5befa1c975
4 changed files with 19 additions and 12 deletions

View File

@ -118,14 +118,18 @@ export class Connection{
};
me._connection.onMessage.addListener(listener);
me._connection.postMessage(message.message);
//TBD: needs to be aware if there is a pinentry pending
// setTimeout(
// function(){
// me.disconnect();
// reject(GPGMEJS_Error('CONN_TIMEOUT'));
// }, timeout);
let timeout = new Promise(function(resolve, reject){
setTimeout(function(){
reject(GPGMEJS_Error('CONN_TIMEOUT'));
}, 5000);
});
if (permittedOperations[message.operation].pinentry){
return me._connection.postMessage(message.message);
} else {
return Promise.race([timeout,
me._connection.postMessage(message.message)
]);
}
});
}
};

View File

@ -104,12 +104,12 @@ export function GPGMEJS_Error(code = 'GENERIC_ERROR'){
if (errors.hasOwnProperty(code)){
code = 'GENERIC_ERROR';
}
if (error.type === 'error'){
if (errors.type === 'error'){
return {code: 'code',
msg: errors[code].msg
};
}
if (error.type === 'warning'){
if (errors.type === 'warning'){
console.log(code + ': ' + error[code].msg);
}
return undefined;

View File

@ -23,6 +23,8 @@
* operation: <Object>
required: Array<String>
optional: Array<String>
pinentry: Boolean If a pinentry dialog is expected, and a timeout of
5000 ms would be too short
answer: <Object>
type: <String< The content type of answer expected
data: Array<String> The payload property of the answer. May be
@ -59,6 +61,7 @@ export const permittedOperations = {
},
decrypt: {
pinentry: true,
required: ['data'],
optional: [
'protocol',

View File

@ -33,7 +33,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('answer').value = answer.data;
}
}, function(errormsg){
alert('Error: '+ errormsg);
alert( errormsg.code + ' ' + errormsg.msg);
});
});
@ -47,7 +47,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('answer').value = answer.data;
}
}, function(errormsg){
alert('Error: '+ errormsg);
alert( errormsg.code + ' ' + errormsg.msg);
});
});
},