From eabe7ea22039e661ad9516d7b26d04ad8a172470 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 5 Jun 2011 10:54:25 -0700 Subject: [PATCH] extract data from payload before responding to http request --- pusher.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pusher.js b/pusher.js index 5f25411..5a12a45 100755 --- a/pusher.js +++ b/pusher.js @@ -171,17 +171,24 @@ function routeRequest(req, res) { return } + try { + var action + , owner = payload.repository.owner.name + , repo = payload.repository.name + , ref = payload.ref + , branch = ref.match(/^refs\/heads\//) ? ref.split('/')[2] : null + , tag = ref.match(/^refs\/tags\//) ? ref.split('/')[2] : null + , refType = branch ? 'branch' : tag ? 'tag' : 'unknown' + } catch (e) { + console.error('!!! malformed payload: ' + e) + console.error(e.stack) + badRequest(req, res) + return + } + res.writeHead(204) res.end() - var action - , owner = payload.repository.owner.name - , repo = payload.repository.name - , ref = payload.ref - , branch = ref.match(/^refs\/heads\//) ? ref.split('/')[2] : null - , tag = ref.match(/^refs\/tags\//) ? ref.split('/')[2] : null - , refType = branch ? 'branch' : tag ? 'tag' : 'unknown' - if (payload.created) { action = 'create' }