ngx-http-retry
Advanced tools
Comparing version 0.0.0-dev.5 to 0.0.1
@@ -17,3 +17,3 @@ (function (global, factory) { | ||
var shouldRetry = retryStrategy && counts[retryStrategyIndex] < retryStrategy.maxCount; | ||
var retryDelay = retryStrategy && retryStrategy.delayFn ? retryStrategy.delayFn(counts[retryStrategyIndex]) : undefined; | ||
var retryDelay = retryStrategy && retryStrategy.delayFn ? retryStrategy.delayFn(counts[retryStrategyIndex]) : 0; | ||
if (!shouldRetry && retryStrategy && retryStrategy.onFailure) { | ||
@@ -20,0 +20,0 @@ retryStrategy.onFailure(error); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common/http"),require("rxjs/observable/of"),require("rxjs/observable/throw"),require("rxjs/operators"),require("rxjs/Subject")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common/http","rxjs/observable/of","rxjs/observable/throw","rxjs/operators","rxjs/Subject"],t):t(e["ngx-http-retry"]={},e.ng.core,e.ng.common.http,e.Rx.Observable,e.Rx.Observable,e.Rx.Observable.prototype,e.Rx)}(this,function(e,t,i,s,p,c,r){"use strict";var n=new t.InjectionToken("HTTP_REQUEST_RETRY_STRATEGIES");function a(u){var a={};function t(e){return e.pipe(c.switchMap(function(t){if(t instanceof i.HttpErrorResponse){var e=u.findIndex(function(e){return e.statuses.includes(t.status)}),r=-1<e?u[e]:undefined;a[e]=(a[e]||0)+1;var n=r&&a[e]<r.maxCount,o=r&&r.delayFn?r.delayFn(a[e]):undefined;return!n&&r&&r.onFailure&&r.onFailure(t),n?s.of(t).pipe(c.delay(o)):p._throw(t)}}))}return function(e){return e.pipe(c.retryWhen(t))}}var d=new r.Subject,o=function(){this.httpRetryFailures=d.asObservable()};o.decorators=[{type:t.Injectable}],o.ctorParameters=function(){return[]};var f="X-Request-Attempt-Number",u=function(){function e(e){this.retryStrategies=e}return e.prototype.intercept=function(r,n){var e,o=this;if("GET"===r.method.toUpperCase()){var u=0;e=s.of(undefined).pipe(c.tap(function(){u++}),c.switchMap(function(){return n.handle((t=u,(e=r).clone({headers:e.headers.append(f,t.toString())})));var e,t}),a(this.retryStrategies),c.tap(undefined,function(t){t instanceof i.HttpErrorResponse&&(o.retryStrategies.some(function(e){return e.statuses.includes(t.status)})&&d.next(t))}))}else e=n.handle(r);return e},e}();u.decorators=[{type:t.Injectable}],u.ctorParameters=function(){return[{type:Array,decorators:[{type:t.Inject,args:[n]}]}]};var l={provide:i.HTTP_INTERCEPTORS,useClass:u,multi:!0};var y=function(){function e(e){if(e)throw new Error("NgxHttpRetryModule is already loaded. Import it only once (e.g. in your AppModule or CoreModule).")}return e.forRoot=function(){return{ngModule:e,providers:[o,l]}},e}();y.decorators=[{type:t.NgModule,args:[{imports:[i.HttpClientModule]}]}],y.ctorParameters=function(){return[{type:y,decorators:[{type:t.Optional},{type:t.SkipSelf}]}]},e.HTTP_REQUEST_RETRY_STRATEGIES=n,e.httpRequestRetry=a,e.NgxHttpRetryService=o,e.NgxHttpRetryModule=y,e.ɵa=u,e.ɵb=l,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common/http"),require("rxjs/observable/of"),require("rxjs/observable/throw"),require("rxjs/operators"),require("rxjs/Subject")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common/http","rxjs/observable/of","rxjs/observable/throw","rxjs/operators","rxjs/Subject"],t):t(e["ngx-http-retry"]={},e.ng.core,e.ng.common.http,e.Rx.Observable,e.Rx.Observable,e.Rx.Observable.prototype,e.Rx)}(this,function(e,t,s,i,p,c,r){"use strict";var n=new t.InjectionToken("HTTP_REQUEST_RETRY_STRATEGIES");function u(a){var u={};function t(e){return e.pipe(c.switchMap(function(t){if(t instanceof s.HttpErrorResponse){var e=a.findIndex(function(e){return e.statuses.includes(t.status)}),r=-1<e?a[e]:undefined;u[e]=(u[e]||0)+1;var n=r&&u[e]<r.maxCount,o=r&&r.delayFn?r.delayFn(u[e]):0;return!n&&r&&r.onFailure&&r.onFailure(t),n?i.of(t).pipe(c.delay(o)):p._throw(t)}}))}return function(e){return e.pipe(c.retryWhen(t))}}var d=new r.Subject,o=function(){this.httpRetryFailures=d.asObservable()};o.decorators=[{type:t.Injectable}],o.ctorParameters=function(){return[]};var f="X-Request-Attempt-Number",a=function(){function e(e){this.retryStrategies=e}return e.prototype.intercept=function(r,n){var e,o=this;if("GET"===r.method.toUpperCase()){var a=0;e=i.of(undefined).pipe(c.tap(function(){a++}),c.switchMap(function(){return n.handle((t=a,(e=r).clone({headers:e.headers.append(f,t.toString())})));var e,t}),u(this.retryStrategies),c.tap(undefined,function(t){t instanceof s.HttpErrorResponse&&(o.retryStrategies.some(function(e){return e.statuses.includes(t.status)})&&d.next(t))}))}else e=n.handle(r);return e},e}();a.decorators=[{type:t.Injectable}],a.ctorParameters=function(){return[{type:Array,decorators:[{type:t.Inject,args:[n]}]}]};var l={provide:s.HTTP_INTERCEPTORS,useClass:a,multi:!0};var y=function(){function e(e){if(e)throw new Error("NgxHttpRetryModule is already loaded. Import it only once (e.g. in your AppModule or CoreModule).")}return e.forRoot=function(){return{ngModule:e,providers:[o,l]}},e}();y.decorators=[{type:t.NgModule,args:[{imports:[s.HttpClientModule]}]}],y.ctorParameters=function(){return[{type:y,decorators:[{type:t.Optional},{type:t.SkipSelf}]}]},e.HTTP_REQUEST_RETRY_STRATEGIES=n,e.httpRequestRetry=u,e.NgxHttpRetryService=o,e.NgxHttpRetryModule=y,e.ɵa=a,e.ɵb=l,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ngx-http-retry.umd.min.js.map |
@@ -39,3 +39,3 @@ import { InjectionToken, Injectable, Inject, NgModule, Optional, SkipSelf } from '@angular/core'; | ||
const /** @type {?} */ shouldRetry = retryStrategy && counts[retryStrategyIndex] < retryStrategy.maxCount; | ||
const /** @type {?} */ retryDelay = retryStrategy && retryStrategy.delayFn ? retryStrategy.delayFn(counts[retryStrategyIndex]) : undefined; | ||
const /** @type {?} */ retryDelay = retryStrategy && retryStrategy.delayFn ? retryStrategy.delayFn(counts[retryStrategyIndex]) : 0; | ||
if (!shouldRetry && retryStrategy && retryStrategy.onFailure) { | ||
@@ -42,0 +42,0 @@ retryStrategy.onFailure(error); |
@@ -18,3 +18,3 @@ import { InjectionToken, Injectable, Inject, NgModule, Optional, SkipSelf } from '@angular/core'; | ||
var shouldRetry = retryStrategy && counts[retryStrategyIndex] < retryStrategy.maxCount; | ||
var retryDelay = retryStrategy && retryStrategy.delayFn ? retryStrategy.delayFn(counts[retryStrategyIndex]) : undefined; | ||
var retryDelay = retryStrategy && retryStrategy.delayFn ? retryStrategy.delayFn(counts[retryStrategyIndex]) : 0; | ||
if (!shouldRetry && retryStrategy && retryStrategy.onFailure) { | ||
@@ -21,0 +21,0 @@ retryStrategy.onFailure(error); |
{ | ||
"name": "ngx-http-retry", | ||
"version": "0.0.0-dev.5", | ||
"version": "0.0.1", | ||
"repository": "https://github.com/kevinphelps/ngx-libraries", | ||
@@ -5,0 +5,0 @@ "author": "Kevin Phelps", |
@@ -5,3 +5,4 @@ # ngx-http-retry | ||
A configurable Angular HTTP interceptor to retry GET request and respond to errors and flaky connections. | ||
A configurable Angular HTTP interceptor to retry GET requests and respond to errors and flaky | ||
connections. | ||
@@ -32,11 +33,12 @@ ## Installation | ||
You provide a collection of injectable classes that implement `HttpRequestRetryStrategy` interface | ||
using the `HTTP_REQUEST_RETRY_STRATEGIES` `InjectionToken`. This is how you tell `ngx-http-retry` | ||
which status codes to retry, how many times to retry, and when to stop retrying. | ||
You configure `ngx-http-retry` by providing (via Angular dependency injection) a collection of | ||
injectable classes that implement the `HttpRequestRetryStrategy` interface. These "retry strategies" | ||
tell `ngx-http-retry` which status codes to retry, how many times to retry, and when to stop | ||
retrying. | ||
In addition to being thrown by the http request observable like normal, the last `HttpErrorResponse` | ||
before `ngx-http-retry` stops retrying a request is 1) passed to the retry strategy's `onFailure` | ||
method and 2) emitted on the `NgxHttpRetryService`'s `httpRetryFailures` observable. | ||
received when `ngx-http-retry` stops retrying a request is passed to the retry strategy's `onFailure` | ||
method and emitted on the `NgxHttpRetryService`'s `httpRetryFailures` observable. | ||
### Implementing HttpRequestRetryStrategy | ||
### Implementing `HttpRequestRetryStrategy` | ||
@@ -67,3 +69,3 @@ ```typescript | ||
### Using NgxHttpRetryService (optional) | ||
### Using `NgxHttpRetryService` (optional) | ||
@@ -84,4 +86,11 @@ ```typescript | ||
### Request Headers | ||
`ngx-http-retry` will add a header named `X-Request-Attempt-Number` to each request it sends that | ||
with the number of the current attempt. This was added primarily for testing. But it's plausible | ||
that this could be useful information to track on the server in some scenarios, so this header is | ||
added in production. A future version may allow disabling this option if needed. | ||
## License | ||
MIT © [Kevin Phelps](https://kevinphelps.me) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63475
92