import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; import { Observable } from 'rxjs'; import { BaseHttpParams } from '../base-http-params'; import { InterceptorType } from './interceptor-type'; import { environment } from '../../../../environments/environment'; export abstract class BaseInterceptor implements HttpInterceptor { constructor() { } abstract type: InterceptorType; abstract interceptRequest(req: HttpRequest, next: HttpHandler): Observable>; intercept(req: HttpRequest, next: HttpHandler): Observable> { if (this.isApplied(req)) { return this.interceptRequest(req, next); } return next.handle(req); } isApplied(req: HttpRequest): boolean { if (req.params instanceof BaseHttpParams && req.params.interceptorContext && Array.isArray(req.params.interceptorContext.excludedInterceptors) && req.params.interceptorContext.excludedInterceptors.includes(this.type)) { return false; } return (req.params instanceof BaseHttpParams && req.params.interceptorContext && Array.isArray(req.params.interceptorContext.interceptAllRequests) && req.params.interceptorContext.interceptAllRequests.includes(this.type)) || req.url.startsWith(environment.Server); } }