import { ErrorHandler, Injectable } from '@angular/core';
import { ErrorService } from './component/error.service';
import { LoggingService, LogType } from '../services/logging.service';
import { isWhiteList } from '../utils/http-interceptor-whitelist.utils';

@Injectable()
export class HimaSalesErrorHandler implements ErrorHandler {
  constructor(private errorService: ErrorService, private logger: LoggingService) {}

  handleError(error: any): void {
    if (
      // tslint:disable-next-line: quotemark
      error.message === "You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable."
    ) {
      return;
    } else if (error && error.url && error.status && isWhiteList(error.url, error.status)) {
      return;
    } else {
      this.errorService.addErrors(error.status ? error.status : 0, error.message, undefined);
      this.logger.log('HUNGENDUBEL INSTORE MA APP', error, LogType.Error);
    }
  }
}
