import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {HttpSecurityErrorInterceptor} from "@webbpm/base-package";
import {Injectable} from "@angular/core";
import {EMPTY, Observable} from "rxjs";
import {catchError} from "rxjs/operators";

@Injectable()
export class DevHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor
    implements HttpInterceptor {

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    if (window.location.hash.includes("webbpm-preview")) {
      return next.handle(req).pipe(catchError(() => {
                                                return EMPTY;
                                              }
      ));
    }
    else {
      return super.intercept(req, next);
    }
  }
}
