File

src/app/providers/services/routing-lookup.service.ts

Index

Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

Private handleError
handleError(error: HttpErrorResponse)
Parameters :
Name Type Optional
error HttpErrorResponse No
Returns : any
lookup
lookup(routingNumber: string)
Parameters :
Name Type Optional
routingNumber string No
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
const SEARCH_API = 'todo';
export interface Bank {
  id: string;
  rtn: string;
  CustomerName: string;
  RTNName: string;
  ServicingFRB: string;
}

@Injectable()
export class RoutingLookupService {
  constructor(private http: HttpClient) {}

  lookup(routingNumber: string): Observable<Bank | any> {
    return this.http
      .get<Bank[]>(`${SEARCH_API}/routing?number=${routingNumber}`)
      .pipe(
        map(banks => banks[0]),
        catchError(error => {
          return this.handleError(error);
        })
      );
  }

  private handleError(error: HttpErrorResponse) {
    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(
        `Backend 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 ""