@opra/client
Version:
Opra Client package
15 lines (14 loc) • 561 B
JavaScript
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);
}