import { identifierModuleUrl } from '@angular/compiler'; import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { ConfigService } from './config.service'; import { Response, ResponseContentType } from '@angular/http'; import { Observable } from 'rxjs'; import { catchError, map, tap } from 'rxjs/operators'; import { throwError } from 'rxjs'; @Injectable() export class DataService { private api: string; private coursesUrl = 'https://dev.enroll.wisc.edu/api/planner/v1/degreePlan/519261/courses'; private log: any; constructor(private http: HttpClient, private configService: ConfigService) { this.api = this.configService.apiUrl; } getCourseData() { return this.http .get(this.coursesUrl) // .subscribe( // data => console.log('data: ', data), // success path // error => console.log('error: ', error) // error path // ); .pipe( map(this.extractData), catchError(this.errorHandler) ); } private extractData(res: Response) { return res.text() ? res.json() : {}; } private errorHandler(error: Response) { // console.error(error); return throwError(error || 'Server Error'); } }