SWEBDEV Telegram 3464
Angular сервис ErrorHandler с RetryWhen

В Angular сервис ErrorHandler можно расширить для создания продвинутой системы обработки ошибок. Совместно с оператором retryWhen, можно добавить автоматические повторные запросы с экспоненциальной задержкой.

Пример: кастомный ErrorHandler с повторной попыткой запроса.
typescriptimport { Injectable, ErrorHandler } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { retryWhen, delay, scan } from 'rxjs/operators';

@Injectable()
export class CustomErrorHandler implements ErrorHandler {
constructor(private http: HttpClient) {}

retryRequest(url: string) {
this.http.get(url).pipe(
retryWhen(errors =>
errors.pipe(
scan((attempts) => {
if (attempts >= 5) throw errors;
return attempts + 1;
}, 0),
delay(attempts => Math.pow(2, attempts) * 1000) // Экспоненциальная задержка
)
)
).subscribe(data => console.log('Success:', data));
}
}

👉 @sWebDev
👍5



tgoop.com/sWebDev/3464
Create:
Last Update:

Angular сервис ErrorHandler с RetryWhen

В Angular сервис ErrorHandler можно расширить для создания продвинутой системы обработки ошибок. Совместно с оператором retryWhen, можно добавить автоматические повторные запросы с экспоненциальной задержкой.

Пример: кастомный ErrorHandler с повторной попыткой запроса.

typescriptimport { Injectable, ErrorHandler } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { retryWhen, delay, scan } from 'rxjs/operators';

@Injectable()
export class CustomErrorHandler implements ErrorHandler {
constructor(private http: HttpClient) {}

retryRequest(url: string) {
this.http.get(url).pipe(
retryWhen(errors =>
errors.pipe(
scan((attempts) => {
if (attempts >= 5) throw errors;
return attempts + 1;
}, 0),
delay(attempts => Math.pow(2, attempts) * 1000) // Экспоненциальная задержка
)
)
).subscribe(data => console.log('Success:', data));
}
}

👉 @sWebDev

BY Frontender Libs - обзор библиотек JS / CSS




Share with your friend now:
tgoop.com/sWebDev/3464

View MORE
Open in Telegram


Telegram News

Date: |

Image: Telegram. Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. How to Create a Private or Public Channel on Telegram? The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously. Other crimes that the SUCK Channel incited under Ng’s watch included using corrosive chemicals to make explosives and causing grievous bodily harm with intent. The court also found Ng responsible for calling on people to assist protesters who clashed violently with police at several universities in November 2019.
from us


Telegram Frontender Libs - обзор библиотек JS / CSS
FROM American