I'm using the sendgrid library for node.js. Currently there is a callback that it's getting fired twice.
@invite = (email, agencyId, callback) ->
(app.get 'agencies').findOne {_id: agencyId}, {name:1}, (error, agency) ->
sendgrid.send {
to: email,
from: 'yamil.asusta@upr.edu',
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
This is what I get from the console
{ '0': true, '1': undefined }
[Function]
{ '0': false, '1': 'Invalid JSON response from server' }
Invalid JSON response from server
The thing is, I invoke the function from 1 route and it works perfectly fine. If I invoke it from another separate route, it fires the callback but, it says the callback variable (function) is undefined.
Any clues?
I suggest you log the arguments to the @invite function. I suspect that is getting called twice, once with correct arguments and once with incorrect arguments due to a bug elsewhere in your program.