2013-05-26 138 views
2

我爲node.js使用sendgrid庫。目前有一個回調,它被炒了兩次。Node.js回調調用兩次

@invite = (email, agencyId, callback) -> 
    (app.get 'agencies').findOne {_id: agencyId}, {name:1}, (error, agency) -> 
    sendgrid.send { 
     to: email, 
     from: '[email protected]', 
     subject: "You have been invited to #{agency.name}", 
     html: "<html><body>Have fun</a></body></html>" 
    }, (success, message) -> 
     console.log arguments 
     if success 
     console.log callback 
     callback() 
     else 
     console.log message 

這是我從控制檯

{ '0': true, '1': undefined } 
[Function] 
{ '0': false, '1': 'Invalid JSON response from server' } 
Invalid JSON response from server 

的事情是搞定了,我從1路調用函數和它的作品完美的罰款。如果我從另一個單獨的路由調用它,它會觸發回調,但它表示回調變量(函數)未定義。

任何線索?

回答

0

我建議你將參數記錄到@invite函數。我懷疑這會被調用兩次,一次是正確的參數,一次是由於程序中其他地方的錯誤導致錯誤的參數。

+0

我有幾次......它只被調用一次。 – elbuo