import { Injectable } from '@angular/core' ; import { AuthHttp } from 'angular2-jwt' ; import { Observable } from 'rxjs/Observable' ; import './rxjs-operators' ; @ Injectable ( ) export class DataService { constructor ( private authHttp ) { } getSecretQuote ( ) { return this . authHttp . get ( 'http://localhost:3002/api/quote' ) . map ( res => res . json ( ) ) . catch ( this . handleError ) ; } private handleError ( error ) { let errMsg = ( error . message ) ? error . message : error . status ? `${ error . status } - ${ error . statusText }` : 'Server error' ; console . error ( errMsg ) ; return Observable . throw ( errMsg ) ; } }