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:
parent
c72adc0096
commit
5befa1c975
@ -118,14 +118,18 @@ export class Connection{
|
|||||||
};
|
};
|
||||||
|
|
||||||
me._connection.onMessage.addListener(listener);
|
me._connection.onMessage.addListener(listener);
|
||||||
me._connection.postMessage(message.message);
|
let timeout = new Promise(function(resolve, reject){
|
||||||
|
setTimeout(function(){
|
||||||
//TBD: needs to be aware if there is a pinentry pending
|
reject(GPGMEJS_Error('CONN_TIMEOUT'));
|
||||||
// setTimeout(
|
}, 5000);
|
||||||
// function(){
|
});
|
||||||
// me.disconnect();
|
if (permittedOperations[message.operation].pinentry){
|
||||||
// reject(GPGMEJS_Error('CONN_TIMEOUT'));
|
return me._connection.postMessage(message.message);
|
||||||
// }, timeout);
|
} else {
|
||||||
|
return Promise.race([timeout,
|
||||||
|
me._connection.postMessage(message.message)
|
||||||
|
]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -104,12 +104,12 @@ export function GPGMEJS_Error(code = 'GENERIC_ERROR'){
|
|||||||
if (errors.hasOwnProperty(code)){
|
if (errors.hasOwnProperty(code)){
|
||||||
code = 'GENERIC_ERROR';
|
code = 'GENERIC_ERROR';
|
||||||
}
|
}
|
||||||
if (error.type === 'error'){
|
if (errors.type === 'error'){
|
||||||
return {code: 'code',
|
return {code: 'code',
|
||||||
msg: errors[code].msg
|
msg: errors[code].msg
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (error.type === 'warning'){
|
if (errors.type === 'warning'){
|
||||||
console.log(code + ': ' + error[code].msg);
|
console.log(code + ': ' + error[code].msg);
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
* operation: <Object>
|
* operation: <Object>
|
||||||
required: Array<String>
|
required: Array<String>
|
||||||
optional: 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>
|
answer: <Object>
|
||||||
type: <String< The content type of answer expected
|
type: <String< The content type of answer expected
|
||||||
data: Array<String> The payload property of the answer. May be
|
data: Array<String> The payload property of the answer. May be
|
||||||
@ -59,6 +61,7 @@ export const permittedOperations = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
decrypt: {
|
decrypt: {
|
||||||
|
pinentry: true,
|
||||||
required: ['data'],
|
required: ['data'],
|
||||||
optional: [
|
optional: [
|
||||||
'protocol',
|
'protocol',
|
||||||
|
@ -33,7 +33,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
document.getElementById('answer').value = answer.data;
|
document.getElementById('answer').value = answer.data;
|
||||||
}
|
}
|
||||||
}, function(errormsg){
|
}, function(errormsg){
|
||||||
alert('Error: '+ errormsg);
|
alert( errormsg.code + ' ' + errormsg.msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
document.getElementById('answer').value = answer.data;
|
document.getElementById('answer').value = answer.data;
|
||||||
}
|
}
|
||||||
}, function(errormsg){
|
}, function(errormsg){
|
||||||
alert('Error: '+ errormsg);
|
alert( errormsg.code + ' ' + errormsg.msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user