diff --git a/src/services/profiles.ts b/src/services/profiles.ts index 39cd1f6..6106729 100644 --- a/src/services/profiles.ts +++ b/src/services/profiles.ts @@ -5,7 +5,8 @@ import 'rxjs/add/operator/map'; @Injectable() export class ProfileService { - endpoint: string = 'https://api.fitz.guru/urge/profiles'; //'assets/data/profiles.json'; + endpoint: string = 'https://api.fitz.guru/urge/profiles'; + fallback: string = 'assets/data/profiles.json'; idMap: any; profiles: any; @@ -22,14 +23,24 @@ export class ProfileService { return new Promise(resolve => { this.http.get(this.endpoint) .map(res => res.json()) - .subscribe(data => { - this.profiles = data; - this.profiles.reduce((map, profile, i) => { - map[profile._id] = i; - return map; - }, this.idMap); - resolve(this.profiles); - }); + .subscribe( + data => { + this.profiles = data; + this.profiles.reduce((map, profile, i) => { + map[profile._id] = i; + return map; + }, this.idMap); + resolve(this.profiles); + }, + error => { + this.profiles = this.fallback; + this.profiles.reduce((map, profile, i) => { + map[profile._id] = i; + return map; + }, this.idMap); + resolve(this.profiles); + } + ); }); }