     else
       request.end()
 
-    request.on "error", (err) =>
-      @robot.logger.error "Campfire request error: #{err}"
-
+    request.on "error", (err) ->
+      logger.error "Campfire request error: #{err}"
+

        "method" : "GET"
        "headers": headers

      request = HTTPS.request options, (response) =>
        response.setEncoding("utf8")

        buf = ''

        response.on "data", (chunk) =>
          if chunk is ' '
            # campfire api sends a ' ' heartbeat every 3s

          else if chunk.match(/^\s*Access Denied/)
            # errors are not json formatted
            @robot.logger.error "Campfire error: #{chunk}"
            process.exit(1)

          else

      body = new Buffer(body)
      options.headers["Content-Length"] = body.length

    request = HTTPS.request options, (response) ->
      data = ""

      response.on "data", (chunk) ->
        data += chunk

      response.on "end", ->
        if response.statusCode >= 400
          switch response.statusCode
            when 401
              throw new Error "Invalid access token provided, campfire refused the authentication"
            else
              logger.error "Campfire error: #{response.statusCode}"

        try
          callback null, JSON.parse(data)
        catch err
          callback null, data or { }

      response.on "error", (err) ->
        logger.error "Campfire response error: #{err}"
        callback err, { }

    if method is "POST"
