import { HttpClient , HttpErrorResponse , HttpHeaders } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { Store } from '@ngxs/store' ; import { Observable , throwError } from 'rxjs' ; import { ApiOptionalHeadersModel } from './api.model' ; @ Injectable ( { providedIn : 'root' , } ) export class ApiService { constructor ( private store , private http ) { } public httpHeaderOptions ( optionalHeaders ) { return new HttpHeaders ( { ... optionalHeaders , } ) ; } public get ( url , optionalHeaders = { } ) { return this . http . get ( url , { headers : this . httpHeaderOptions ( optionalHeaders ) , } ) ; } public post ( url , body , optionalHeaders = { } ) { return this . http . post ( url , body , { headers : this . httpHeaderOptions ( optionalHeaders ) , } ) ; } public put ( url , body , optionalHeaders = { } ) { return this . http . put ( url , body , { headers : this . httpHeaderOptions ( optionalHeaders ) , } ) ; } private handleError ( operation = 'operation' ) { return ( error ) : Observable < any > => { console . log ( 'status: ' , error . status , ' operation: ' , operation ) ; return throwError ( ( ) => error ) ; } ; } }