mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 04:46:10 +01:00
95bcc21a06
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. ```
25 lines
592 B
JavaScript
25 lines
592 B
JavaScript
module.exports = function (promiseFn) {
|
|
return function () {
|
|
var args = []
|
|
for (var i = 0; i < arguments.length - 1; i++) {
|
|
args.push(arguments[i])
|
|
}
|
|
var cb = arguments[arguments.length - 1]
|
|
|
|
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
|
|
}
|
|
}
|