digininja icon

CoffeeScript undefined is not a function

digininja | PRO | 09/24/16 10:40:19 PM UTC | 0 ⭐ | 10477 👁️ | Never ⏰ | []
CoffeeScript |

950 B

|

None

|

0 👍

/

0 👎

CoffeeScript experts, what is wrong with the script below to cause this error?
 
 
[Tue Sep 20 2016 06:44:41 GMT+0000 (UTC)] ERROR TypeError: undefined is not a function
  at /home/hubot/scripts/hack.coffee:16:13, <js>:11:20
 
 
 
  9     robot.respond /check (.*)/i, (res) ->
 10         host = res.match[1]
 11         robot.http("http://robin.home/check?#{host}").get() (err, res, body) ->
 12             if err
 13                 res.send "Encountered an error :( #{err}"
 14                 return
 15 
 16             res.send "Got back "
 17
 
It is based on the code from here if it helps:
 
https://hubot.github.com/docs/scripting/#making-http-calls
 
----------
 
Fixed it, the variable res was being reused and so stopped being an instance of Response and became an instance of http.ServerResponse instead. I've raised an issue in Github about this to hopefully update the docs and improve clarity.
 
https://github.com/github/hubot/issues/1241

Comments