{"action":"closed","issue":{"url":"https://api.github.com/repos/auth0/webtask-scripts/issues/4","repository_url":"https://api.github.com/repos/auth0/webtask-scripts","labels_url":"https://api.github.com/repos/auth0/webtask-scripts/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/auth0/webtask-scripts/issues/4/comments","events_url":"https://api.github.com/repos/auth0/webtask-scripts/issues/4/events","html_url":"https://github.com/auth0/webtask-scripts/issues/4","id":125695721,"number":4,"title":"github/smarthook.js is sending replying with 500 from the webtask","user":{"login":"ArSn","id":2803693,"avatar_url":"https://avatars.githubusercontent.com/u/2803693?v=3","gravatar_id":"","url":"https://api.github.com/users/ArSn","html_url":"https://github.com/ArSn","followers_url":"https://api.github.com/users/ArSn/followers","following_url":"https://api.github.com/users/ArSn/following{/other_user}","gists_url":"https://api.github.com/users/ArSn/gists{/gist_id}","starred_url":"https://api.github.com/users/ArSn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArSn/subscriptions","organizations_url":"https://api.github.com/users/ArSn/orgs","repos_url":"https://api.github.com/users/ArSn/repos","events_url":"https://api.github.com/users/ArSn/events{/privacy}","received_events_url":"https://api.github.com/users/ArSn/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-08T21:22:08Z","updated_at":"2016-05-25T14:07:54Z","closed_at":"2016-05-25T14:07:54Z","body":"I used this guide to set up a simple github-webhook-connected webtask: https://webtask.io/docs/sample_github\r\n\r\nIt works fine up to the point where the response of the webtask is read by GitHub. This leads to the task working perfectly fine, but the very unattractive side effect that the callback for error and/or success messages does not work properly.\r\n\r\n**Steps to reproduce**\r\n1. Follow guide that is linked above\r\n2. Check deliveries in the settings of your github repo\r\n3. Find HTPP {500} responses here\r\n\r\nLog of **one** execution of the webhook:\r\n```\r\n[20:11:01.939Z]  INFO wt: connected to streaming logs (container=wt-koljaz-***-0)\r\n[20:11:12.779Z]  INFO wt: webtask container assigned\r\n[20:11:13.880Z]  INFO wt: \r\n    {\r\n      \"code\": 500,\r\n      \"error\": \"Script generated an unhandled asynchronous exception.\",\r\n      \"details\": \"ReferenceError: writeHead is not defined\",\r\n      \"name\": \"ReferenceError\",\r\n      \"message\": \"writeHead is not defined\",\r\n      \"stack\": \"ReferenceError: writeHead is not defined\\n    at args (/data/smarthook.js:99:21)\\n    at Request.eval [as _callback] (eval at <anonymous> (/data/smarthook.js:55:69), <anonymous>:49:28)\\n    at Request.self.callback (/data/_verquire/request/2.56.0/node_modules/request/request.js:354:22)\\n    at Request.emit (events.js:110:17)\\n    at Request.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1207:14)\\n    at Request.emit (events.js:129:20)\\n    at IncomingMessage.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1153:12)\\n    at IncomingMessage.emit (events.js:129:20)\\n    at _stream_readable.js:908:16\\n    at process._tickDomainCallback (node.js:381:11)\"\r\n    }\r\n[20:11:13.880Z]  INFO wt: \r\n    {\r\n      \"code\": 500,\r\n      \"error\": \"Script generated an unhandled asynchronous exception.\",\r\n      \"details\": \"ReferenceError: writeHead is not defined\",\r\n      \"name\": \"ReferenceError\",\r\n      \"message\": \"writeHead is not defined\",\r\n      \"stack\": \"ReferenceError: writeHead is not defined\\n    at args (/data/smarthook.js:99:21)\\n    at Request.eval [as _callback] (eval at <anonymous> (/data/smarthook.js:55:69), <anonymous>:49:28)\\n    at Request.self.callback (/data/_verquire/request/2.56.0/node_modules/request/request.js:354:22)\\n    at Request.emit (events.js:110:17)\\n    at Request.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1207:14)\\n    at Request.emit (events.js:129:20)\\n    at IncomingMessage.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1153:12)\\n    at IncomingMessage.emit (events.js:129:20)\\n    at _stream_readable.js:908:16\\n    at process._tickDomainCallback (node.js:381:11)\"\r\n    }\r\n[20:11:13.882Z]  INFO wt: \r\n    {\r\n      \"code\": 500,\r\n      \"error\": \"Script generated an unhandled asynchronous exception.\",\r\n      \"details\": \"ReferenceError: writeHead is not defined\",\r\n      \"name\": \"ReferenceError\",\r\n      \"message\": \"writeHead is not defined\",\r\n      \"stack\": \"ReferenceError: writeHead is not defined\\n    at args (/data/smarthook.js:99:21)\\n    at Request.eval [as _callback] (eval at <anonymous> (/data/smarthook.js:55:69), <anonymous>:49:28)\\n    at Request.self.callback (/data/_verquire/request/2.56.0/node_modules/request/request.js:354:22)\\n    at Request.emit (events.js:110:17)\\n    at Request.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1207:14)\\n    at Request.emit (events.js:129:20)\\n    at IncomingMessage.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1153:12)\\n    at IncomingMessage.emit (events.js:129:20)\\n    at _stream_readable.js:908:16\\n    at process._tickDomainCallback (node.js:381:11)\"\r\n    }\r\n[20:11:13.882Z]  INFO wt: \r\n    {\r\n      \"code\": 500,\r\n      \"error\": \"Script generated an unhandled asynchronous exception.\",\r\n      \"details\": \"ReferenceError: writeHead is not defined\",\r\n      \"name\": \"ReferenceError\",\r\n      \"message\": \"writeHead is not defined\",\r\n      \"stack\": \"ReferenceError: writeHead is not defined\\n    at args (/data/smarthook.js:99:21)\\n    at Request.eval [as _callback] (eval at <anonymous> (/data/smarthook.js:55:69), <anonymous>:49:28)\\n    at Request.self.callback (/data/_verquire/request/2.56.0/node_modules/request/request.js:354:22)\\n    at Request.emit (events.js:110:17)\\n    at Request.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1207:14)\\n    at Request.emit (events.js:129:20)\\n    at IncomingMessage.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1153:12)\\n    at IncomingMessage.emit (events.js:129:20)\\n    at _stream_readable.js:908:16\\n    at process._tickDomainCallback (node.js:381:11)\"\r\n    }\r\n[20:11:13.883Z]  INFO wt: \r\n    Code generated an uncaught exception:  ReferenceError: writeHead is not defined\r\n        at args (/data/smarthook.js:99:21)\r\n        at Request.eval [as _callback] (eval at <anonymous> (/data/smarthook.js:55:69), <anonymous>:49:28)\r\n        at Request.self.callback (/data/_verquire/request/2.56.0/node_modules/request/request.js:354:22)\r\n        at Request.emit (events.js:110:17)\r\n        at Request.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1207:14)\r\n        at Request.emit (events.js:129:20)\r\n        at IncomingMessage.<anonymous> (/data/_verquire/request/2.56.0/node_modules/request/request.js:1153:12)\r\n        at IncomingMessage.emit (events.js:129:20)\r\n        at _stream_readable.js:908:16\r\n        at process._tickDomainCallback (node.js:381:11)\r\n[20:11:14.533Z]  INFO wt: webtask container recycled\r\n```\r\n\r\nThe problem here seems to be that the writeHead() is not a function in this scope, but rather has to be called on the response (`res`). Adding this actually solves the issue, the log looks afterwards like:\r\n```\r\n[20:31:30.122Z]  INFO wt: connected to streaming logs (container=wt-koljaz-***-0)\r\n[20:32:35.974Z]  INFO wt: webtask container assigned\r\n[20:33:25.738Z]  INFO wt: webtask container recycled\r\n```\r\n\r\nAnd the responses are with valid codes, for both errors and successes. I will send a pull request to fix this shortly."}}
{"actor":{"display_login":"chenkie"}}