Skip to content

Instantly share code, notes, and snippets.

@oleh-zaporozhets
Created October 23, 2021 18:57
Show Gist options
  • Save oleh-zaporozhets/b27e4ddc69d63bda2afa85405ef5a7c4 to your computer and use it in GitHub Desktop.
Save oleh-zaporozhets/b27e4ddc69d63bda2afa85405ef5a7c4 to your computer and use it in GitHub Desktop.
class TestHttp extends Http {
constructor() {
super('http://localhost:5000/');
}
public test() {
return this.instance.get('/test');
}
}
async function main() {
const testHttp = new TestHttp();
const errorHandler = (err: AxiosError) => {
console.log(err.message);
return err?.response?.status === 429;
};
const testCircuitBreaker = new CircuitBreakerWithEmitter(testHttp, {
timeout: 10_000,
errorHandler,
});
testCircuitBreaker.on('OPEN', () => {
console.log('CIRCUIT BREAKER WAS OPENED');
});
testCircuitBreaker.on('CLOSE', async () => {
console.log('CIRCUIT BREAKER WAS CLOSED');
});
setInterval(() => {
testHttp.test().catch(() => {});
}, 2000);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment