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. 4
      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){ zeroClient.sendAsync(payload, function onPayloadHandled(err, response){
if (err) throw err if (err) throw err
// console.log('MetaMaskPlugin - RPC complete:', payload, '->', response) // console.log('MetaMaskPlugin - RPC complete:', payload, '->', response)
remotePort.postMessage(response) try {
remotePort.postMessage(response)
} catch (_) {
// port disconnected
}
}) })
} }

@ -20,3 +20,7 @@ var pluginStream = new PortStream(pluginPort)
// forward communication across // forward communication across
pageStream.pipe(pluginStream) 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() var remoteProvider = new StreamProvider()
remoteProvider.pipe(pluginStream).pipe(remoteProvider) remoteProvider.pipe(pluginStream).pipe(remoteProvider)
pluginStream.on('error', console.error.bind(console))
remoteProvider.on('error', console.error.bind(console))
// handle synchronous methods remotely // handle synchronous methods remotely
// handle accounts cache // handle accounts cache

@ -37,8 +37,13 @@ PortDuplexStream.prototype._read = noop
PortDuplexStream.prototype._write = function(msg, encoding, cb){ PortDuplexStream.prototype._write = function(msg, encoding, cb){
// console.log('PortDuplexStream - sent message', msg) // console.log('PortDuplexStream - sent message', msg)
this._port.postMessage(msg) try {
cb() this._port.postMessage(msg)
cb()
} catch(err){
// this.emit('error', err)
cb(new Error('PortDuplexStream - disconnected'))
}
} }
// util // util

Loading…
Cancel
Save