import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, of } from 'rxjs'; import { ISType } from './ISType'; import { types } from './types'; @Injectable({ providedIn: 'root' }) export class IsService { constructor(private httpClient: HttpClient) { } /* NextNext Token */ private token = ''; /** * Handle Http operation that failed. * Let the app continue. * @param operation - name of the operation that failed * @param result - optional value to return as the observable result */ private handleError(operation = 'operation', result?: T) { return (error: any): Observable => { console.error(error); console.error(`${operation} failed: ${error.message}`); // log to console instead // Let the app keep running by returning an empty result. return of(result as T); }; } public getResourceTypes(callback: (isTypes: ISType[]) => void): void { const url = 'http://pc-frosini.isti.cnr.it:8080/resource-registry/types/Resource?polymorphic=true&gcube-token=' + this.token; // const observable: Observable = of(types); const observable: Observable = this.httpClient.get(url); /* observable.pipe( tap(_ => console.info('Fetched Resource Types')), catchError(this.handleError('getResourceTypes()', types)) ); */ observable.subscribe(data => callback(data)); } }