mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
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. ```
This commit is contained in:
parent
df0b89074b
commit
95bcc21a06
@ -6,12 +6,19 @@ module.exports = function (promiseFn) {
|
|||||||
}
|
}
|
||||||
var cb = arguments[arguments.length - 1]
|
var cb = arguments[arguments.length - 1]
|
||||||
|
|
||||||
return promiseFn.apply(this, args)
|
const nodeified = promiseFn.apply(this, args)
|
||||||
.then(function (result) {
|
|
||||||
|
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)
|
cb(null, result)
|
||||||
})
|
})
|
||||||
.catch(function (reason) {
|
.catch(function (reason) {
|
||||||
cb(reason)
|
cb(reason)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return nodeified
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user