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

Additional param in errorFilter option #489

Closed
vizhukova opened this issue Nov 11, 2020 · 2 comments · Fixed by #492 · May be fixed by #884
Closed

Additional param in errorFilter option #489

vizhukova opened this issue Nov 11, 2020 · 2 comments · Fixed by #492 · May be fixed by #884
Assignees

Comments

@vizhukova
Copy link

Hello, opossum team!

I've got a question about expansion errorFilter functionality.
Initial data:
The breaker once defined in the project and reused by every request
I need to ignore errors only for one request (as it is expected behavior and I need to call query until it response success)
So I expect something like that

const breaker = new CircuitBreaker(asyncFunction, {
      name,
      timeout,
      resetTimeout,
      errorFilter: (err, query) => {
       if(err.code === 'SOME_ERROR_CODE' && query === 'some')
     },
    })

Is it possible to add another one query param to the errorFilter?

Thanks in advance,
Veronika

@lance
Copy link
Member

lance commented Nov 13, 2020

Hi @vizhukova it's not clear what you expect query to be in this case. Would it work to pass the parameters originally provided to the failing asyncFunction? Specifically here in handleError:

opossum/lib/circuit.js

Lines 648 to 655 in 32762f4

function handleError (error, circuit, timeout, args, latency, resolve, reject) {
clearTimeout(timeout);
if (circuit.options.errorFilter(error)) {
circuit.emit('success', error, latency);
} else {
fail(circuit, error, args, latency);
}

If line 651 looked instead like

  if (circuit.options.errorFilter(error, args)) {

Would this solve the problem?

@vizhukova
Copy link
Author

Yeah! This will help

@lance lance self-assigned this Nov 17, 2020
lance added a commit to lance/opossum that referenced this issue Nov 17, 2020
When the circuit invocation fails, and there is an error filter in place,
this change provides the function invocation parameters as the second
parameter to `errorFilter()`.

Fixes: nodeshift#489

Signed-off-by: Lance Ball <lball@redhat.com>
helio-frota pushed a commit that referenced this issue Nov 23, 2020
When the circuit invocation fails, and there is an error filter in place,
this change provides the function invocation parameters as the second
parameter to `errorFilter()`.

Fixes: #489

Signed-off-by: Lance Ball <lball@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants