UNPKG

@opra/client

Version:
15 lines (14 loc) 561 B
export class HttpInterceptorHandler { constructor(interceptors, finalHandler) { this.chain = interceptors.reduceRight((chainTailFn, interceptor) => (initialRequest, handler) => interceptor.intercept(initialRequest, { handle: downstreamRequest => chainTailFn(downstreamRequest, handler), }), chainEnd); this.finalHandler = finalHandler; } handle(initialRequest) { return this.chain(initialRequest, req => this.finalHandler.handle(req)); } } function chainEnd(req, handler) { return handler(req); }