Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular retry interceptor

content_copy
import {retry, tap} from 'rxjs/operators';
export const RETRY_COUNT = new HttpContextToken(() => 3);
export const ERROR_COUNT = new HttpContextToken(() => 0);

export class RetryInterceptor implements HttpInterceptor {
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    const retryCount = req.context.get(RETRY_COUNT);

    return next.handle(req).pipe(
        tap({
              // An error has occurred, so increment this request's ERROR_COUNT.
             error: () => req.context.set(ERROR_COUNT, req.context.get(ERROR_COUNT) + 1)
            }),
        // Retry the request a configurable number of times.
        retry(retryCount),
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js loop through function arguments 
Javascript :: multiple conditions for JavaScript .includes() method 
Javascript :: how to import modules js 
Javascript :: vue nuxt vuex store watch 
Javascript :: cancel an event in javascript 
Javascript :: check if div contains background image 
Javascript :: get value of textarea jquery 
Javascript :: jest spyon 
Javascript :: Scaling an image to fit on canvas 
Javascript :: prevent onclick event javascript 
Javascript :: Accessing Object Properties with Variables 
Javascript :: Vue 3 script setup props emits 
Javascript :: js object sort 
Javascript :: js style 
Javascript :: Using Then To Create A Promise In JavaScript 
Javascript :: break in if statement js 
Javascript :: reddit fetch api js 
Javascript :: js empty map 
Javascript :: onclick hold react 
Javascript :: sort array of objects in ascending order in js 
Javascript :: get the location of an item in an array 
Javascript :: javascript closure function example 
Javascript :: javascript array multidimensional push 
Javascript :: import and export type in js 
Javascript :: js url pathname 
Javascript :: scroll out js threshold 
Javascript :: nestjs typeorm 
Javascript :: this.setstate is not a function in react native 
Javascript :: how to concatenate a string in javascript 
Javascript :: Simple interest in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =