How to catch error in Observable.forkJoin(…)?

You may catch the error in each of your observables that are being passed to forkJoin: // Imports that support chaining of operators in older versions of RxJS import {Observable} from ‘rxjs/Observable’; import {forkJoin} from ‘rxjs/add/observable/forkJoin’; import {of} from ‘rxjs/add/observable/of’; import {map} from ‘rxjs/add/operator/map’; import {catch} from ‘rxjs/add/operator/catch’; // Code with chaining operators in older … Read more

How to make an http call every 2 minutes with RXJS?

Since you are already using Observables, simply make full use of it 🙂 Obersvable.interval() is your good friend here: In your component, do this: Observable .interval(2*60*1000) .timeInterval() .mergeMap(() => this.notificationService.getNotifications(this.token)) .subscribe(data => { console.log(data); }); Explanation: .interval() creates an observable that emits an event every 2 minutes. .timeInterval() convert an Observable that emits items into … Read more

How to read response headers in angularjs?

Use the headers variable in success and error callbacks From documentation. $http.get(‘/someUrl’). success(function(data, status, headers, config) { // this callback will be called asynchronously // when the response is available }) .error(function(data, status, headers, config) { // called asynchronously if an error occurs // or server returns response with an error status. }); If you … Read more

How to handle unauthorized requests(status with 401 or 403) with new httpClient in angular 4.3

You should use your interceptor and just handle it like this: @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private router: Router) { } private handleAuthError(err: HttpErrorResponse): Observable<any> { //handle your auth error or rethrow if (err.status === 401 || err.status === 403) { //navigate /delete cookies or whatever this.router.navigateByUrl(`/login`); // if you’ve caught / handled … Read more

How to read JSON error response from $http if responseType is arraybuffer

Edit: As @Paul LeBeau points out, my answer assumes that the response is ASCII encoded. Basically you just need to decode the ArrayBuffer into a string and use JSON.parse(). var decodedString = String.fromCharCode.apply(null, new Uint8Array(data)); var obj = JSON.parse(decodedString); var message = obj[‘message’]; I ran tests in IE11 & Chrome and this works just fine.

Angular 2 http get not getting

Http uses rxjs and is a cold/lazy observable, meaning that you should subscribe to it to make it work. this.http.get(`http://swapi.co/api/people/1`) .map((response: Response) => { console.log(response.json()); response.json(); }) .subscribe(); Or if you want to subscribe from somewhere else, you should return the http.get method like this: getAllPersons(): Observable <any> { console.log(“Here”); return this.http.get(`http://swapi.co/api/people/1`) .map((response: Response) => … Read more

Angularjs autocomplete from $http

I made an autocomplete directive and uploaded it to GitHub. It should also be able to handle data from an HTTP-Request. Here’s the demo: http://justgoscha.github.io/allmighty-autocomplete/ And here the documentation and repository: https://github.com/JustGoscha/allmighty-autocomplete So basically you have to return a promise when you want to get data from an HTTP request, that gets resolved when the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)