import { Injectable } from '@angular/core' ; import { environment } from '../../../environments/environment' ; import { HttpHeaders , HttpClient , HttpParams } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { JwtService } from './jwt.service' ; import { throwError } from 'rxjs' ; import { catchError } from 'rxjs/operators' ; @ Injectable ( ) export class ApiService { constructor ( private http , private jwtService ) { } private formatErrors ( error ) { return throwError ( error . error ) ; } get ( path , params = new HttpParams ( ) ) { return this . http . get ( `${ environment . api_url }${ path }` , { params } ) . pipe ( catchError ( this . formatErrors ) ) ; } put ( path , body = { } ) { return this . http . put ( `${ environment . api_url }${ path }` , JSON . stringify ( body ) ) . pipe ( catchError ( this . formatErrors ) ) ; } post ( path , body = { } ) { return this . http . post ( `${ environment . api_url }${ path }` , JSON . stringify ( body ) ) . pipe ( catchError ( this . formatErrors ) ) ; } delete ( path ) { return this . http . delete ( `${ environment . api_url }${ path }` ) . pipe ( catchError ( this . formatErrors ) ) ; } }