mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
context wiring - handle and log errors
This commit is contained in:
parent
ebf60843fa
commit
066996396f
@ -76,7 +76,11 @@ function onRpcRequest(remotePort, payload){
|
||||
zeroClient.sendAsync(payload, function onPayloadHandled(err, response){
|
||||
if (err) throw err
|
||||
// console.log('MetaMaskPlugin - RPC complete:', payload, '->', response)
|
||||
remotePort.postMessage(response)
|
||||
try {
|
||||
remotePort.postMessage(response)
|
||||
} catch (_) {
|
||||
// port disconnected
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -19,4 +19,8 @@ var pluginStream = new PortStream(pluginPort)
|
||||
|
||||
// forward communication across
|
||||
pageStream.pipe(pluginStream)
|
||||
pluginStream.pipe(pageStream)
|
||||
pluginStream.pipe(pageStream)
|
||||
|
||||
// log errors
|
||||
pageStream.on('error', console.error.bind(console))
|
||||
pluginStream.on('error', console.error.bind(console))
|
@ -12,6 +12,9 @@ var pluginStream = new LocalMessageDuplexStream({
|
||||
var remoteProvider = new StreamProvider()
|
||||
remoteProvider.pipe(pluginStream).pipe(remoteProvider)
|
||||
|
||||
pluginStream.on('error', console.error.bind(console))
|
||||
remoteProvider.on('error', console.error.bind(console))
|
||||
|
||||
// handle synchronous methods remotely
|
||||
|
||||
// handle accounts cache
|
||||
|
@ -37,8 +37,13 @@ PortDuplexStream.prototype._read = noop
|
||||
|
||||
PortDuplexStream.prototype._write = function(msg, encoding, cb){
|
||||
// console.log('PortDuplexStream - sent message', msg)
|
||||
this._port.postMessage(msg)
|
||||
cb()
|
||||
try {
|
||||
this._port.postMessage(msg)
|
||||
cb()
|
||||
} catch(err){
|
||||
// this.emit('error', err)
|
||||
cb(new Error('PortDuplexStream - disconnected'))
|
||||
}
|
||||
}
|
||||
|
||||
// util
|
||||
|
Loading…
Reference in New Issue
Block a user