 pagerNoop               = false if pagerNoop is "false" or pagerNoop  is "off"
 
 module.exports = (robot) ->
+
+  class PagerDutyError extends Error
+
   http = (path) ->
     auth =
     HttpClient.create("#{pagerDutyBaseUrl}#{path}")

    query =
      status:  status
      sort_by: "incident_number:asc"
    pagerduty.get msg, "/incidents", query, (json) ->
      cb(json.incidents)

  pagerduty =

      .query(query)
      .get() (err, res, body) ->
        if err?
          if cb.length is 1
            robot.emit 'error', err, msg
          else
            cb(err)
          return
        json_body = null
        switch res.statusCode
          when 200 then json_body = JSON.parse(body)
          else
            if cb.length is 1
              console.log res.statusCode
              console.log body
              json_body = null
            else
              cb(new PagerDutyError("#{res.statusCode} back from #{url}"))
              return

        if cb.length is 1
          cb json_body
        else
          cb null, json_body

  missingEnvironmentForApi = (msg) ->
    missingAnything = false
