blob: efb3ad3e69b247e28f2903558903945de5ff4fc8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import { Injectable } from "@angular/core";
import {
HttpClient,
HttpHeaders,
HttpErrorResponse
} from "@angular/common/http";
import { Observable, of } from "rxjs";
import { map, catchError, tap } from "rxjs/operators";
const httpOptions = {
headers: new HttpHeaders({
"Content-Type": "application/json"
})
};
@Injectable({
providedIn: "root"
})
export class RestApiService {
constructor(private http: HttpClient) {}
private extractData(res: Response) {
let body = res;
return body || {};
}
private handleError<T>(operation = "operation", result?: T) {
return (error: any): Observable<T> => {
// TODO: send the error to remote logging infrastructure
console.error(error); // log to console instead
// TODO: better job of transforming error for user consumption
console.log(`${operation} failed: ${error.message}`);
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
getTopics(): Observable<any> {
return this.http.get("/topics/dmaap/").pipe(map(this.extractData));
}
/*
updateProduct (id, product): Observable<any> {
return this.http.put(endpoint + 'products/' + id, JSON.stringify(product), httpOptions).pipe(
tap(_ => console.log(`updated product id=${id}`)),
catchError(this.handleError<any>('updateProduct'))
);
}
*/
}
|