1
|
/**
|
2
|
* Created by stefania on 7/17/17.
|
3
|
*/
|
4
|
import {Injectable} from "@angular/core";
|
5
|
import {Http, Response} from "@angular/http";
|
6
|
import {Observable} from "rxjs/Rx";
|
7
|
import {PageContent} from "../domain/page-content";
|
8
|
|
9
|
|
10
|
@Injectable()
|
11
|
export class HelpContentService {
|
12
|
|
13
|
private _helpServiceUrl = process.env.FAQ_ENDPOINT;
|
14
|
|
15
|
constructor(private http: Http) {
|
16
|
}
|
17
|
|
18
|
getActivePageContent(route: string) {
|
19
|
return this.http.get(this._helpServiceUrl + "/page/route?q=" + route)
|
20
|
.map(res => <PageContent> res.json())
|
21
|
.catch(this.handleError);
|
22
|
}
|
23
|
|
24
|
private extractData(res: Response) {
|
25
|
let body = res.json();
|
26
|
return body.data || {};
|
27
|
}
|
28
|
|
29
|
private handleError(error: Response | any) {
|
30
|
// In a real world app, we might use a remote logging infrastructure
|
31
|
// We'd also dig deeper into the error to get a better message
|
32
|
let errMsg = "";
|
33
|
console.log(error);
|
34
|
if (error instanceof Response) {
|
35
|
const body = error.text() || '';
|
36
|
//const err = body.error || JSON.stringify(body);
|
37
|
errMsg = `${error.status} - ${error.statusText || ''} ${body}`;
|
38
|
} else {
|
39
|
errMsg = (error.message) ? error.message :
|
40
|
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
|
41
|
console.error(errMsg); // log to console instead
|
42
|
}
|
43
|
return Observable.throw(errMsg);
|
44
|
}
|
45
|
}
|