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: |

Over 33,000 people sent out over 1,000 doxxing messages in the group. Although the administrators tried to delete all of the messages, the posting speed was far too much for them to keep up. For crypto enthusiasts, there was the “gm” app, a self-described “meme app” which only allowed users to greet each other with “gm,” or “good morning,” a common acronym thrown around on Crypto Twitter and Discord. But the gm app was shut down back in September after a hacker reportedly gained access to user data. On Tuesday, some local media outlets included Sing Tao Daily cited sources as saying the Hong Kong government was considering restricting access to Telegram. Privacy Commissioner for Personal Data Ada Chung told to the Legislative Council on Monday that government officials, police and lawmakers remain the targets of “doxxing” despite a privacy law amendment last year that criminalised the malicious disclosure of personal information. Public channels are public to the internet, regardless of whether or not they are subscribed. A public channel is displayed in search results and has a short address (link). Content is editable within two days of publishing
from us


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