/*
 * Copyright (c) 2017, Hugo Freire <hugo@exec.sh>.
 *
 * This source code is licensed under the license found in the
 * LICENSE file in the root directory of this source tree.
 */

const Request = require('request-on-steroids')

const Promise = require('bluebird')

const Health = require('health-checkup')

class RtpPlayRequest extends Request {
  constructor (options) {
    super(options)

    Health.addCheck('rtp-play', () => new Promise((resolve, reject) => {
      if (this.circuitBreaker.isOpen()) {
        return reject(new Error(`circuit breaker is open`))
      } else {
        return resolve()
      }
    }))
  }
}

module.exports = new RtpPlayRequest()

@@ -430,20 +430,16 @@
 ) =%3E
- new
  Promise
 ((re
@@ -438,25 +438,14 @@
 mise
-((resolve, reject
+.try((
 ) =%3E
@@ -501,22 +501,14 @@
     
-return reject(
+throw 
 new 
@@ -543,49 +543,8 @@
 en%60)
-)%0A      %7D else %7B%0A        return resolve()
 %0A   

refactor circuit breaker healthcheck