Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.execute swallows the error? #85

Open
murbanowicz opened this issue Dec 20, 2023 · 1 comment
Open

.execute swallows the error? #85

murbanowicz opened this issue Dec 20, 2023 · 1 comment

Comments

@murbanowicz
Copy link

Hi!
I am likely doing something wrong, but nothing comes obvious from the docs, unfortunately.

This is what I do in the constructor:

    this.retryPolicy = retry(
      handleWhen((err) => !(err instanceof OptimisticLockError)),
      {
        maxAttempts: configService.get('RESILIENCY_MAX_RETRIES'),
        backoff: new ExponentialBackoff(),
      },
    );

    this.circuitBreaker = ctCircuitBreaker(handleAll, {
      halfOpenAfter: configService.get('CIRCUIT_BREAKER_HALF_OPEN_AFTER'),
      breaker: new ConsecutiveBreaker(
        // +1 for the initial request. Has to be aligned with retries to get it working properly
        configService.get('RESILIENCY_MAX_RETRIES') + 1,
      ),
    });

    this.resiliencePolicy = wrap(this.retryPolicy, this.circuitBreaker);
  }

When I try to do:

  public async flush() {
    return await this.resiliencePolicy.execute(() =>
      this.repository.getEntityManager().flush(),
    );

The top level flush function is not throwing, even though the this.repository.getEntityManager().flush() is throwing, which results in completely bad behaviour of the app.

The error is basically swallowed by the execute function.

@connor4312
Copy link
Owner

connor4312 commented Dec 20, 2023

The execute will either return the successful result or propagate the last error the retryPolicy encountered. If you want to observe errors thrown from the circuit breaker, or failures during the retry, you can use policy.onFailure (docs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants