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