Node-ACl抛出未处理的拒绝错误 [英] Node-ACl throws uhandled rejection error
问题描述
我在我的快速应用程序中使用ACL模块。在服务器启动时,我使用acl.allow()函数定义了一些角色及其权限。
i am using ACL module in my express application.At the start of the server i define some roles and their permissions using the acl.allow() function.
但它记录了一个错误,说明了未定义的拒绝类型。错误param给出回调时错误消失。但我不确定是什么引发了错误以及应该如何处理错误。
But it logs in a error saying undefined rejection type.The error vanishes on giving a callback with error param.But i am not very sure about what is throwing the error and how it should be handled.
我使用的代码片段是:
var aclmodule = new acl(new acl.mongodbBackend(config.db.URL, "accesscontrol_"));
aclmodule.allow([
{
roles:['rolea'],
allows:[
{resources:['a','b'], permissions:['*']}
]
},
{
roles:['roleb','rolec'],
allows:[
{resources:['a'], permissions:['view']}
]
},
{
roles:['rolec'],
allows:[
{resources:['o'], permissions:['view','edit']}
]
}
]);
});
控制台中记录的错误是:
The error logged in console is :
未处理拒绝TypeError:undefined不是D:\ user \web \ myapp-web \ node_modules \ acl \lib \ mongodb-backend中的函数
。 js:119:15
Unhandled rejection TypeError: undefined is not a function at D:\user\web\myapp-web\node_modules\acl\lib\mongodb-backend.js:119:15
at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async.
js:607:21
在D:\ myapp \web \ myapp -web\\\
ode_modules\acl\\\
ode_modules\async\lib\async。
js:246:17
at iterate(D:\ myapp \web \ myapp-web \ node_modules \ acl \ node_modules \ async \ l
ib \\ \\ async.js:146:13)async.eachSeries的
(D:\ myapp \web \ myapp-web \ node_modules \ acl \ node_module
s \ async \ lib \async.js:162:9)_asyncMap上的
(D:\ myapp \web \ myapp-web \ node_modules \ acl \ node_modules \ async
\lib \\ async.js:245:13)
at Object.mapSeries(D:\ myapp \web \ myapp-web \ node_modules \ acl \ node_module
s \ async \ lib \async.js:228:23)在Object.async.series上的
(D:\ myapp \web \ myapp-web \ node_modules \ acl \ node_mod
ules \ async \lib \ async.js:605:19)
at Object.MongoDBBackend.end(D:\ myapp \web \ myapp-web \ node_modules \ acl \ li
b\mongodb-backend.js:35:11)Obje的
ct.tryCatcher(D:\ myapp \web \ myapp-web \ node_modules \ acl \\\
ode_modul
es\bluebird\js \\\\\\\\\\\\\\\\\\\\\\\\在Object.ret [作为endAsync]的
(eval at(D:\ myapp\web \ myapp-web
\ node_modules \ acl \ node_modules \bluebird \ js \ main \promisify.js:163:12),
js:607:21 at D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\lib\async. js:246:17 at iterate (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async\l ib\async.js:146:13) at async.eachSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module s\async\lib\async.js:162:9) at _asyncMap (D:\myapp\web\myapp-web\node_modules\acl\node_modules\async \lib\async.js:245:13) at Object.mapSeries (D:\myapp\web\myapp-web\node_modules\acl\node_module s\async\lib\async.js:228:23) at Object.async.series (D:\myapp\web\myapp-web\node_modules\acl\node_mod ules\async\lib\async.js:605:19) at Object.MongoDBBackend.end (D:\myapp\web\myapp-web\node_modules\acl\li b\mongodb-backend.js:35:11) at Object.tryCatcher (D:\myapp\web\myapp-web\node_modules\acl\node_modul es\bluebird\js\main\util.js:26:23) at Object.ret [as endAsync] (eval at (D:\myapp\web\myapp-web \node_modules\acl\node_modules\bluebird\js\main\promisify.js:163:12),
推荐答案
config.db.URL
一个字符串?如果是这样,这是导致错误的原因。它失败的线是(在 mongodb-backend.js
):
Is config.db.URL
a string? If so, this is the cause of your errors. The line it is failing on is (in mongodb-backend.js
):
self.db.collection(...
- 它说 .collection()
是未定义的。(如果自我会有意义.db只是一个字符串。)
self.db.collection(...
-- it is saying that .collection()
is undefined. (Which would make sense if "self.db" were only a string.)
创建新的 mongodbBackend时,Node-acl需要数据库实例 / code>,如在文档中说明 - 示例:
Node-acl expects a database instance when creating a new mongodbBackend
, like it says in the docs -- for example:
mongoose.connection.on('connected', function() {
var myAcl = new acl(new acl.mongodbBackend(mongoose.connection.db));
});
这篇关于Node-ACl抛出未处理的拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!