src/extensions.js
function onClientPreRequestCircuitBreaker (ctx, next) {
  if (ctx._config.circuitBreaker.enabled) {
    // any pattern represent an own circuit breaker
    const circuitBreaker = ctx._circuitBreakerMap.get(ctx.trace$.method);
    if (!circuitBreaker) {
      const cb = new CircuitBreaker(ctx._config.circuitBreaker);
      ctx._circuitBreakerMap.set(ctx.trace$.method, cb);
    } else {
      if (!circuitBreaker.available()) {
        // trigger half-open timer
        circuitBreaker.record();
        return next(new Errors.CircuitBreakerError(
          `Circuit breaker is ${circuitBreaker.state}`,
          { state: circuitBreaker.state, method: ctx.trace$.method, service: ctx.trace$.service }));
      }
    }

    next();
  } else {
    next();
  }
}
function onClientPreRequestCircuitBreaker (ctx, next) {
  if (ctx._config.circuitBreaker.enabled) {
    // any pattern represent an own circuit breaker
    const circuitBreaker = ctx._circuitBreakerMap.get(ctx.trace$.method);
    if (!circuitBreaker) {
      const cb = new CircuitBreaker(ctx._config.circuitBreaker);
      ctx._circuitBreakerMap.set(ctx.trace$.method, cb);
    } else {
      if (!circuitBreaker.available()) {
        // trigger half-open timer
        circuitBreaker.record();
        return next(new Errors.CircuitBreakerError(
          `Circuit breaker is ${circuitBreaker.state}`,
          { state: circuitBreaker.state, method: ctx.trace$.method, service: ctx.trace$.service }));
      }
    }

    next();
  } else {
    next();
  }
}
function onClientPreRequestCircuitBreaker ( ctx , next ) { if ( ctx . _config . circuitBreaker . enabled ) { // any pattern represent an own circuit breaker const circuitBreaker = ctx . _circuitBreakerMap . get ( ctx . trace$ . method ) ; if ( ! circuitBreaker ) { const cb = new CircuitBreaker ( ctx . _config . circuitBreaker ) ; ctx . _circuitBreakerMap . set ( ctx . trace$ . method , cb ) ; } else { if ( ! circuitBreaker . available ( ) ) { // trigger half-open timer circuitBreaker . record ( ) ; return next ( new Errors . CircuitBreakerError ( ` ${ circuitBreaker . state } ` , { state : circuitBreaker . state , method : ctx . trace$ . method , service : ctx . trace$ . service } ) ) ; } } next ( ) ; } else { next ( ) ; } }
circuit breaker on client side
circuit breaker on client side