     @robot = robot
     @failing = []
 
-  error: (e) ->
-    console.log "jenkins-notify error: #{error}. Data: #{req.body}"
-    console.log error.stack
+  reset: () ->
+    @failing = []
+
+  error: (err, body) ->
+    console.log "jenkins-notify error: #{err.message}. Data: #{util.inspect(body)}"
+    console.log err.stack
 
   shouldNotify: (notstrat, data) ->
     if data.build.status == 'FAILURE'


url = require('url')
querystring = require('querystring')


class JenkinsNotifier

    try
      # Newer versions of express/hubot already process posts that have Content-Type application/json
      for key of req.body
        # breaks in 0.11
        if key == '__proto__'
          continue
        data = JSON.parse key
        break
    catch err
      @error err, req.body
      try
        data = req.body
      catch error
        @error err, req.body
        return

    if typeof data.build != 'object'
      @error new Error("Unable to process data"), req.body
      return

    if data.build.phase == 'FINISHED'
      if data.build.status == 'FAILURE'
