Add useful nodeify error message

If a nodified method does not return a Promise, it will throw an error, like this:
```
Error in event handler for (unknown): Error: The function setSelectedAccount did not return a Promise, but was nodeified.
```
feature/default_network_editable
Dan Finlay 8 years ago
parent df0b89074b
commit 95bcc21a06
  1. 11
      app/scripts/lib/nodeify.js

@ -6,12 +6,19 @@ module.exports = function (promiseFn) {
}
var cb = arguments[arguments.length - 1]
return promiseFn.apply(this, args)
.then(function (result) {
const nodeified = promiseFn.apply(this, args)
if (!nodeified) {
const methodName = String(promiseFn).split('(')[0]
throw new Error(`The ${methodName} did not return a Promise, but was nodeified.`)
}
nodeified.then(function (result) {
cb(null, result)
})
.catch(function (reason) {
cb(reason)
})
return nodeified
}
}

Loading…
Cancel
Save