File

src/app/providers/services/fi-logo.service.ts

Index

Methods

Constructor

constructor(http: HttpClient, errorService: ErrorStore, sanitizer: DomSanitizer)
Parameters :
Name Type Optional
http HttpClient No
errorService ErrorStore No
sanitizer DomSanitizer No

Methods

getlogo
getlogo(routingNumber: string)
Parameters :
Name Type Optional
routingNumber string No
Returns : Observable<SafeUrl>
Private handleError
handleError(error: HttpErrorResponse)
Parameters :
Name Type Optional
error HttpErrorResponse No
Returns : any
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { catchError } from 'rxjs/operators/catchError';

import { TEMPLATE_API, ERROR_MESSAGE } from '../../app.constants';
import { map } from 'rxjs/operators/map';
import { ErrorStore } from '../stores/error.store';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';

export interface ILogoResponse {
  logoUrl: string
};

@Injectable()
export class FILogoService {
  constructor(
    private http: HttpClient,
    private errorService: ErrorStore,
    private sanitizer: DomSanitizer,
  ) { }

  getlogo(routingNumber: string): Observable<SafeUrl> {
    return this.http.get<ILogoResponse>(`${TEMPLATE_API}/getlogo?routingNumber=${routingNumber}`).pipe(
      map(response => {
        if (!response || !response.logoUrl || response.logoUrl.length === 0) {
          return null;
        }
        return this.sanitizer.bypassSecurityTrustResourceUrl(response.logoUrl);
      }),
      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 new ErrorObservable(
      'Something bad happened; please try again later.'
    );
  }
}

results matching ""

    No results matching ""