SUPER_OLEG_DEV Telegram 91
Привет!

У Angular ну очень классное API для HTTP Interceptors:

```
(request, next) => next(request)
```

Где next(request) возвращает response.

И для сравнения API у axios - https://axios-http.com/docs/interceptors

Это закрывает просто все необходимые кейсы:
- изменить параметры запроса
- вернуть кастомный ответ или ошибку
- модифицировать ответ или ошибку

Забираю в tramvai и депрекейчу накиданные мной на коленке страшные modifyResponse, modifyRequest и modifyError коллбэки для встроенного HTTP клиента)

Правда Angular создает инстанс Observable при вызове next, в tramvai Rx не используется, и будут обычные промисы:


[
// меняем параметры запроса
(req, next) => next({ ...req, timeout: 1000 }),

// модифицируем ответ
(req, next) => next(req)
.then((res) => ({ ...res, payload: 'Intercepted' }),

// модифицируем ошибку
(req, next) => next(req)
.catch((reason) => {
Object.assign(reason, { code: 'INTERCEPTED_ERROR' });
throw reason;
},
]

Мелкая фича, но всегда очень приятно встретить и позаимствовать лаконичное и функциональное API
🔥12👍3



tgoop.com/super_oleg_dev/91
Create:
Last Update:

Привет!

У Angular ну очень классное API для HTTP Interceptors:

```
(request, next) => next(request)
```

Где next(request) возвращает response.

И для сравнения API у axios - https://axios-http.com/docs/interceptors

Это закрывает просто все необходимые кейсы:
- изменить параметры запроса
- вернуть кастомный ответ или ошибку
- модифицировать ответ или ошибку

Забираю в tramvai и депрекейчу накиданные мной на коленке страшные modifyResponse, modifyRequest и modifyError коллбэки для встроенного HTTP клиента)

Правда Angular создает инстанс Observable при вызове next, в tramvai Rx не используется, и будут обычные промисы:


[
// меняем параметры запроса
(req, next) => next({ ...req, timeout: 1000 }),

// модифицируем ответ
(req, next) => next(req)
.then((res) => ({ ...res, payload: 'Intercepted' }),

// модифицируем ошибку
(req, next) => next(req)
.catch((reason) => {
Object.assign(reason, { code: 'INTERCEPTED_ERROR' });
throw reason;
},
]

Мелкая фича, но всегда очень приятно встретить и позаимствовать лаконичное и функциональное API

BY SuperOleg dev notes


Share with your friend now:
tgoop.com/super_oleg_dev/91

View MORE
Open in Telegram


Telegram News

Date: |

Although some crypto traders have moved toward screaming as a coping mechanism, several mental health experts call this therapy a pseudoscience. The crypto community finds its way to engage in one or the other way and share its feelings with other fellow members. Those being doxxed include outgoing Chief Executive Carrie Lam Cheng Yuet-ngor, Chung and police assistant commissioner Joe Chan Tung, who heads police's cyber security and technology crime bureau. As the broader market downturn continues, yelling online has become the crypto trader’s latest coping mechanism after the rise of Goblintown Ethereum NFTs at the end of May and beginning of June, where holders made incoherent groaning sounds and role-played as urine-loving goblin creatures in late-night Twitter Spaces. "Doxxing content is forbidden on Telegram and our moderators routinely remove such content from around the world," said a spokesman for the messaging app, Remi Vaughn. Judge Hui described Ng as inciting others to “commit a massacre” with three posts teaching people to make “toxic chlorine gas bombs,” target police stations, police quarters and the city’s metro stations. This offence was “rather serious,” the court said.
from us


Telegram SuperOleg dev notes
FROM American