1 import { Injectable } from '@angular/core';
2 import { Observable, of, EMPTY } from 'rxjs';
3 import { Vorgang } from './vorgang';
4 import { HttpClient, HttpHeaders } from '@angular/common/http';
5 import { catchError, tap } from 'rxjs/operators';
11 export class VorgangService {
13 gpsUrl = 'http://localhost:1991/las/'; // URL to web api
15 headers: new HttpHeaders({
16 'Content-Type': 'text/plain',
17 'Accept': 'application/json'
21 constructor(private http: HttpClient) { }
23 /** POST: Einen neuen Vorgang erzeugen */
24 create(vorgang: Vorgang): Observable<Vorgang> {
28 this.getUrlSave(vorgang.vbId),
32 tap((result: Vorgang) => this.log(`Result for ${JSON.stringify(vorgang)}: ${JSON.stringify(result)}`)),
33 catchError(this.handleError<Vorgang>('create')));
36 getUrlSave(vbId: string): string {
37 return this.gpsUrl + vbId + '/save';
41 * Handle Http operation that failed.
42 * Let the app continue.
43 * @param operation - name of the operation that failed
44 * @param result - optional value to return as the observable result
46 private handleError<T>(operation = 'operation', result?: T) {
47 return (error: any): Observable<T> => {
49 // TODO: send the error to remote logging infrastructure
50 console.error(error); // log to console instead
52 // TODO: better job of transforming error for user consumption
53 this.log(`${operation} failed: ${error.message}`);
55 // Let the app keep running by returning an empty result.
56 if (result === undefined) {
57 return EMPTY as Observable<T>;
59 return of(result as T);
64 private log(message: string) {