File

src/app/modules/acculynk/providers/acculynk.service.ts

Index

Methods

Constructor

constructor(http: HttpClient, errorStore: ErrorStore)
Parameters :
Name Type Optional
http HttpClient No
errorStore ErrorStore No

Methods

getAccuLynkData
getAccuLynkData(from: string, to: string)
Parameters :
Name Type Optional
from string No
to string No
Returns : any
Private handleError
handleError(error: HttpErrorResponse, message: string)
Parameters :
Name Type Optional
error HttpErrorResponse No
message string No
Returns : any
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { API_ROOT } from '../../../app.constants';
import { ErrorStore } from '../../../providers/stores';
import { IAccuLynkRow } from '../models/acculynkrow';

@Injectable({
  providedIn: 'root'
})
export class AccuLynkService {
  constructor(private http: HttpClient, private errorStore: ErrorStore) {}

  getAccuLynkData(from: string, to: string) {
    const url = `${API_ROOT}/acculynk?from=${from}&to=${to}`;

    return this.http.get<IAccuLynkRow[]>(url).pipe(
      catchError(error => {
        return this.handleError(error, 'Unable to retrieve AccuLynk data');
      })
    );
  }

  private handleError(error: HttpErrorResponse, message: string) {
    const title = 'AccuLynk Data Retrieval Error';
    this.errorStore.showError(title, message);
    if (error.error instanceof ErrorEvent) {
      // A client-side or network error occurred. Handle it accordingly.
      console.error('An error occurred:', error.error.message);
    } else {
      // The backend returned an unsuccessful response code.
      // The response body may contain clues as to what went wrong,
      console.error(
        `Server returned code ${error.status}, ` + `body was: ${error.error}`
      );
    }
    // return an ErrorObservable with a user-facing error message
    return throwError('Something bad happened; please try again later.');
  }
}

result-matching ""

    No results matching ""