Comments (10)
Tried taking off async
and toPromise()
from makeRequest, but still outputs the same error
export class AppComponent implements OnInit {
title = 'app';
private makeRequest () {
return this.http.get(`https://jsonplaceholder.typicode.com/posts/1`);
}
constructor(private http: HttpClient) {}
ngOnInit() {
const route = 'https://jsonplaceholder.typicode.com/posts/1';
const circuitBreakerOptions = {
timeout: 500,
maxFailures: 3,
resetTimeout: 5000
};
const circuit = circuitBreaker(this.makeRequest, circuitBreakerOptions);
circuit.fallback(() => `unavailable right now. Try later.`);
circuit.on('success', (result) => JSON.stringify(result));
circuit.fire().catch((e) => console.error(e));
}
}
from opossum.
So i thought that since Angular http module returns an Observable and not a Promise, I added axios to the project. Still gives me the error, tho
export class AppComponent implements OnInit {
title = 'app';
constructor(private http: HttpClient) {}
private makeRequest(): Promise<any> {
return this.http.get(`https://jsonplaceholder.typicode.com/posts/1`).toPromise();
}
ngOnInit() {
this.makeRequest()
.then((data) => {
console.log(data);
});
const circuitBreakerOptions = {};
const circuit = circuitBreaker(() => axios.get(`https://jsonplaceholder.typicode.com/posts/1`), circuitBreakerOptions);
circuit.fallback(() => `unavailable right now. Try later.`);
circuit
.fire()
.then(data => console.log(data))
.catch((e) => console.error(e));
}
}
So I tried to put the code on another enviroment. Copied and pasted the code on a repl and it worked!
Since i'm at work right now, the network is blocking repl.it from saving the code, but i'll paste it here
the site is: https://repl.it
let opossum = require('opossum');
let axios = require('axios');
const makeRequest = () => {
return axios.get(`https://jsonplaceholder.typicode.com/posts/1`);
};
// axios.get(`https://jsonplaceholder.typicode.com/posts/1`)
// .then(data => console.log(data))
// .catch(error => console.error(error))
const circuitBreakerOptions = {};
const circuit = circuitBreaker(
() => axios.get(`https://jsonplaceholder.typicode.com/posts/1`),
circuitBreakerOptions
);
circuit.fallback(() => `unavailable right now. Try later.`);
circuit.fire().then(data => console.log(data)).catch(e => console.error(e));
from opossum.
This looks like it could be a transpilation issue with TypeScript. Would it be possible for you to provide a small piece of code that would allow me to reproduce the error locally?
from opossum.
Here's the repo with the code I was trying to run:
https://github.com/DavideCarvalho/angular-opossum-issue
from opossum.
I've reproduced this, and it's definitely something going on between the typescript compilation and webpack-ing. But I can't quite figure out what it is.
I'm not very familiar with Angular, but it seems that using the window object is frowned upon. You can see here where opossum sets the circuitBreaker
object in either the global window
object or in module.exports
. I can see in the browser console, that window.circuitBreaker
exists and is a function. But I don't understand Angular and how it works well enough to know why it's not being assigned in the import
statement.
from opossum.
@DavideCarvalho I have pushed a branch which I believe addresses your issues. Can you please test against https://github.com/bucharest-gold/opossum/tree/182-fix-browser-for-angular? If this works for you, I will merge and push a new release.
from opossum.
Okay, Iāl test it when I get home. Thank you for everything
from opossum.
Hello lance, sorry for the wait. I've managed to test the branch right now and worked like a charm!
from opossum.
@DavideCarvalho good news. I have a couple of other tasks to take care of, and then I will spin a new release.
from opossum.
@DavideCarvalho I have merged the pull request and published 1.5.0. Enjoy!
from opossum.
Related Issues (20)
- Is there any way to use circuit breaker with resolver functions of graphql server? HOT 3
- Feature request: resetTimeout and half-open state without a timer. HOT 1
- Reset stats in CircuitBreaker instance HOT 4
- Breaker State Initialization not working as documented HOT 9
- Support Node.js 20 HOT 4
- Is there a reason you are mixing rest parameters and Array.prototype.slice calls in the same functions? HOT 1
- Automated publish fails using Node 16 HOT 2
- Engines does not include Node 19 HOT 2
- Abort controller is controlling at the breaker level, not for each run HOT 3
- Question - best way to implement in a serverless environment with concurrent executions HOT 1
- Feature request: add an option to disable stats snapshots HOT 3
- Lack of Count-Based Rolling Window HOT 3
- different thresholds for different error types HOT 3
- Half open state allowing all requests HOT 1
- Setting some options to `0` doesn't work (it still uses defaults) HOT 2
- Max stack depth exceeded when benchmarking HOT 9
- How can I get single CB for whole HTTP Client with Opossum? HOT 5
- Create the opossum circuit breaker in node js as a Singleton instance HOT 3
- Internal method can be overwritten HOT 4
- Suggestion: Change `CircuitBreaker` type declaration HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opossum.