Hi,
I am trying to read a RSS/JSON from my own server and I am always getting this error:
{"_body":{"isTrusted":true},"status":0,"ok":false,"statusText":"","headers":{},"type":3,"url":null}
Here is my code:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class FeedService {
private feedUrl:string = 'http://www.myserver.com/feed/json';
constructor(private http: Http) {}
getItems(): Observable<any[]> {
return this.http.get(this.feedUrl)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
for (var i = 0; i < body.length; i++) {
if ( body[i].thumbnail ) {
body[i].thumbnail = body[i].thumbnail.split(',')[0].replace(' ', '?');
}
body[i].interested = localStorage.getItem(body[i].id + 'Interested') === 'true' || false;
body[i].going = localStorage.getItem(body[i].id + 'Going') === 'true' || false;
body[i].ignore = localStorage.getItem(body[i].id + 'Ignore') === 'true' || false;
console.log('extractData', body);
}
return body || { };
}
private handleError (error: any) {
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'RSS Server error';
console.error(error);
return Observable.throw(errMsg);
}
}
Any help, please?