-
Notifications
You must be signed in to change notification settings - Fork 107
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
Integrating opossum with axios #509
Comments
Hi @matteodisabatino - a few things going on here. First of all, you should only be creating a single Regarding the fallback function behavior, it's perhaps a little unintuitive (and maybe better docs are needed). If you provide a fallback function there are two possiblities. the fallback succeeds or it fails. In either case, the Scenario 1: If the fallback succeeds, the call to Here is your code rewritten to illustrate this. const axios = require('axios')
const CircuitBreaker = require('./');
const breaker = new CircuitBreaker(axios, {
timeout: 3000,
errorThresholdPercentage: 50,
resetTimeout: 3000
})
breaker.fallback(fArgs => { console.log('FUNCTION FALLBACK, fArgs: ', fArgs); return Promise.reject('Fallback failed')})
breaker.on('halfOpen', fArgs => console.log('EVENT halfOpen, fArgs: ', fArgs))
breaker.on('close', fArgs => console.log('EVENT close, fArgs: ', fArgs))
breaker.on('open', fArgs => console.log('EVENT open, fArgs: ', fArgs))
breaker.on('shutdown', fArgs => console.log('EVENT shutdown, fArgs: ', fArgs))
breaker.on('fire', fArgs => console.log('EVENT fire, fArgs: ', fArgs))
breaker.on('cacheHit', fArgs => console.log('EVENT cacheHit, fArgs: ', fArgs))
breaker.on('cacheMiss', fArgs => console.log('EVENT cacheMiss, fArgs: ', fArgs))
breaker.on('reject', fArgs => console.log('EVENT reject, fArgs: ', fArgs))
breaker.on('timeout', fArgs => console.log('EVENT timeout, fArgs: ', fArgs))
breaker.on('success', fArgs => console.log('EVENT success, fArgs: ', fArgs))
breaker.on('semaphoreLocked', fArgs => console.log('EVENT semaphoreLocked, fArgs: ', fArgs))
breaker.on('healthCheckFailed', fArgs => console.log('EVENT healthCheckFailed, fArgs: ', fArgs))
breaker.on('fallback', fArgs => console.log('EVENT fallback, fArgs: ', fArgs))
breaker.on('failure', fArgs => console.log('EVENT failure, fArgs: ', fArgs))
async function main() {
return await breaker.fire({
method: 'POST',
url: 'http//www.mywebsite.com'
})
}
main()
.then(v => console.log('SUCCESS', v))
.catch(e => console.error('FAILURE', e)) Which produces...
If you change the fallback to return
One thing I did notice while looking into this is that if the fallback function throws instead of just returning a rejected
This is most definitely a bug. /cc @lholmquist @helio-frota |
@lance thank you very much for your clear explanation :-). |
When a fallback function is called and throws an exception, the circuit breaker should catch the exception and return a rejected Promise. See: nodeshift#509 Signed-off-by: Lance Ball <lball@redhat.com>
When a fallback function is called and throws an exception, the circuit breaker should catch the exception and return a rejected Promise. See: #509 Signed-off-by: Lance Ball <lball@redhat.com>
Closing this now that #510 has been merged. Will release a new version to npm soonish |
Release with the bug fix is now released as 5.1.1 on npm |
Hi,
I'm trying to integrate oppossum with axios but I noticed a strage behaviour (in my opinion):
I'm trying to make an HTTP request that must fail with and without opossum.
Without opossum I make the request this way and it works as excepted:
Instead with opossum I make the request this way:
In particular, in the second case, I receive this output:
Since the route I'm trying to call doesn't exist, I receive 404 and axios (correctly) throws and exception; so I expected that opossum to have thrown an exception too. Instead it doesn't happen: opossum says the request is completed with success.
Could someone explain me why this strange behaviour?
The text was updated successfully, but these errors were encountered: