UNPKG

angular-http-interceptor

Version:
1 lines 2.94 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/http"),require("rxjs/Observable"),require("rxjs/add/operator/do"),require("rxjs/add/observable/forkJoin"),require("rxjs/add/operator/concat"),require("rxjs/add/operator/defaultIfEmpty"),require("rxjs/add/observable/of"),require("rxjs/add/operator/catch"),require("rxjs/add/operator/skip")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/http","rxjs/Observable","rxjs/add/operator/do","rxjs/add/observable/forkJoin","rxjs/add/operator/concat","rxjs/add/operator/defaultIfEmpty","rxjs/add/observable/of","rxjs/add/operator/catch","rxjs/add/operator/skip"],t):t(e.angularHttpInterceptor={},e.ng.core,e.ng.http,e.Rx)}(this,function(e,r,n,p){"use strict";var o,a=function(){function e(){}return e.decorators=[{type:r.Injectable}],e}(),t=this&&this.__extends||(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},function(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),s=function(i){function e(e,t,r){var o=i.call(this,t,r)||this;return e instanceof Array?o.interceptors=e:o.interceptors=[e],o}return t(e,i),e.prototype.request=function(e,t){var r=this.mapToRequest(e,t),o=this.interceptors.map(function(e){var t=e.before(r);return null==t?p.Observable.empty().defaultIfEmpty("EMPTY_BEFORE"):t.defaultIfEmpty("EMPTY_BEFORE")}),n=p.Observable.forkJoin(o),a=i.prototype.request.call(this,e,t),s=n.concat(a).skip(1);return this.intercept(s)},e.prototype.intercept=function(e){var t=this;return e.do(function(e){t.emitAfter(e)}).catch(function(e){return t.emitError(e),p.Observable.of(e)})},e.prototype.emitAfter=function(e){for(var t=0,r=this.interceptors;t<r.length;t++){r[t].after(e)}},e.prototype.emitError=function(e){for(var t=0,r=this.interceptors;t<r.length;t++){r[t].error(e)}},e.prototype.mapToRequest=function(e,t){var r;if("string"==typeof e&&t)t.url=e,r=t;else if("string"==typeof e){var o=new n.RequestOptions({url:e});o.headers=new n.Headers,r=o}else r=e;return r},e.decorators=[{type:r.Injectable}],e.ctorParameters=function(){return[{type:void 0,decorators:[{type:r.Inject,args:[a]}]},{type:n.XHRBackend},{type:n.RequestOptions}]},e}(n.Http),i=new r.InjectionToken("Interceptor"),u=function(){function t(){}return t.withInterceptors=function(e){return{ngModule:t,providers:[e,{provide:n.Http,useFactory:c,deps:[i,n.XHRBackend,n.RequestOptions]},{provide:s,useExisting:n.Http}]}},t.decorators=[{type:r.NgModule,args:[{providers:[{provide:n.Http,useFactory:c,deps:[a,n.XHRBackend,n.RequestOptions]},{provide:s,useExisting:n.Http}]}]}],t}();function c(e,t,r){return new s(e,t,r)}e.CustomHttp=s,e.INTERCEPTORS=i,e.InterceptorModule=u,e.httpFactory=c,e.Interceptor=a,Object.defineProperty(e,"__esModule",{value:!0})});