如何在OrientDB中捕获承诺错误?

时间:2016-09-01 17:22:28

标签: promise try-catch orientdb es6-promise

UPDATE: this is not a problem of code. Code works as it should.

I've restarted OrientDB server for few times and then it works as it should.

So, the problem was in OrientDB server, not the code.

Seems like there is no timeout for promise result. So, when I was calling `db.class.get` the promise was stuck without invocation of  `then` or `catch`.
  

我的问题出现是因为罕见的巧合。代码工作正常。

例如,为什么我在尝试上课时无法获得回调以捕获错误?

请看这个例子 - http://orientdb.com/docs/master/OrientJS-Class-Classes.html#getting-classes

现在,当我这样做时:

db.class.get('Player')
.then(
    function(player){
        console.log('Retrieved class: ' + player.name);
    }
)
.catch(
    function(err){
        console.log('Getting class Player error:',err)
    }
);

实际上没有记录任何内容。没有错误,没有成功。

这不仅是我发现的'假的'承诺。 我认为OrientDB的教程非常有限。

那么,我怎样才能在上课时发现错误?

1 个答案:

答案 0 :(得分:1)

我已经尝试过您的代码,在我看来,它有效!

一开始,我没有创建课程" Player"事实上,你的代码给了我以下输出:

Getting class Player error: { OrientDB.RequestError: No such class: Player
    at Db.<anonymous> (C:\Users\Alberto Brunetti\node_modules\orientjs\lib\db\class\index.js:296:64)
    at Db.tryCatcher (C:\Users\Alberto Brunetti\node_modules\bluebird\js\main\util.js:26:23)
    at Promise._settlePromiseFromHandler (C:\Users\Alberto Brunetti\node_modules\bluebird\js\main\promise.js:503:31)
    at Promise._settlePromiseAt (C:\Users\Alberto Brunetti\node_modules\bluebird\js\main\promise.js:577:18)
    at Async._drainQueue (C:\Users\Alberto Brunetti\node_modules\bluebird\js\main\async.js:128:12)
    at Async._drainQueues (C:\Users\Alberto Brunetti\node_modules\bluebird\js\main\async.js:133:10)
    at Immediate.Async.drainQueues (C:\Users\Alberto Brunetti\node_modules\bluebird\js\main\async.js:15:14)
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)
    at processImmediate [as _immediateCallback] (timers.js:533:5)
  name: 'OrientDB.RequestError',
  message: 'No such class: Player',
  data: {} }

在此代码中,您可以看到您期望的错误消息(第一行)。

希望它有所帮助。

相关问题