-
Notifications
You must be signed in to change notification settings - Fork 108
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
Opossum with Angular 5 #182
Comments
Tried taking off 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));
}
} |
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! 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)); |
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? |
Here's the repo with the code I was trying to run: |
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 |
@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. |
Okay, I’l test it when I get home. Thank you for everything |
Hello lance, sorry for the wait. I've managed to test the branch right now and worked like a charm! |
@DavideCarvalho good news. I have a couple of other tasks to take care of, and then I will spin a new release. |
@DavideCarvalho I have merged the pull request and published 1.5.0. Enjoy! |
Node.js Version:
8.9.3
Operating System:
Windows 10
Steps to Produce Error:
I created an Angular application with Angular-cli and added opossum in it.
Then, tried to make a http request with opossum to
https://jsonplaceholder.typicode.com/
, copied and pasted the code on readme into my application, but it throws me this error:I'll paste the code below
The text was updated successfully, but these errors were encountered: