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

Implement _exceptions list #20

Open
pythons1980 opened this issue Jun 16, 2017 · 2 comments
Open

Implement _exceptions list #20

pythons1980 opened this issue Jun 16, 2017 · 2 comments

Comments

@pythons1980
Copy link

Hi All,

it would be nice if function is_system_error can work with self._exceptions as well. I am about to implement ES circuit breaker for just one exception (ES BROKEN CONNECTION) so that I have to create my own Breaker (subclassing CircuitBreaker) and rewrite function is_system_error instead of just define one exception in the new list self._exceptions.

Regards,
Vojtech.

@sebastiandev
Copy link

Yes, I needed something similar and ended up using a callable that check that the error is of the type i want. But that functionality is only in the latest master, not in a release

@yairm210
Copy link

yairm210 commented Mar 14, 2022

Now that some time has passed, it's simple to do this as sebastiandev has said

Including a test for this here, modeled after the existing tests in tests.py:

    def test_allow_whitelist(self):
        """CircuitBreaker: it should allow the user to add a predicate function to determine excluded exceptions.
        """
        acceptableExceptions = [NotImplementedError]
        isUnacceptableException = lambda e: type(e) not in acceptableExceptions

        self.breaker = CircuitBreaker(exclude=[isUnacceptableException])


        def throwsAcceptableError(): raise NotImplementedError
        def throwsUnacceptableError(): raise LookupError

        self.assertRaises(NotImplementedError, self.breaker.call, throwsAcceptableError)
        self.assertEqual(1, self.breaker.fail_counter)

        self.assertRaises(LookupError, self.breaker.call, throwsUnacceptableError)
        self.assertEqual(0, self.breaker.fail_counter)

Also this issue seems to be a copy of #5, so probably one of them should be closed?

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

3 participants