context wiring - handle and log errors

feature/default_network_editable
kumavis 9 years ago
parent ebf60843fa
commit 066996396f
  1. 6
      app/scripts/background.js
  2. 6
      app/scripts/contentscript.js
  3. 3
      app/scripts/inpage.js
  4. 9
      app/scripts/lib/port-stream.js

@ -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…
Cancel
Save