feat: log retries
Log retries commit-id:2346ea7d
This commit is contained in:
parent
1d3190e70d
commit
d141239a22
1 changed files with 19 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
import type { DynamicModule, Provider } from '@nestjs/common';
|
import type { DynamicModule, Provider } from '@nestjs/common';
|
||||||
import { Module } from '@nestjs/common';
|
import { Logger, Module } from '@nestjs/common';
|
||||||
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import axiosRetry, { exponentialDelay } from 'axios-retry';
|
import axiosRetry, { exponentialDelay } from 'axios-retry';
|
||||||
|
@ -13,10 +13,28 @@ import type {
|
||||||
} from './interfaces';
|
} from './interfaces';
|
||||||
|
|
||||||
const createAxiosInstance = (config?: HttpModuleOptions) => {
|
const createAxiosInstance = (config?: HttpModuleOptions) => {
|
||||||
|
const logger = new Logger(HttpService.name);
|
||||||
const axiosInstance = axios.create(config);
|
const axiosInstance = axios.create(config);
|
||||||
axiosRetry(axiosInstance, {
|
axiosRetry(axiosInstance, {
|
||||||
// Default exponential backoff
|
// Default exponential backoff
|
||||||
retryDelay: exponentialDelay,
|
retryDelay: exponentialDelay,
|
||||||
|
onRetry(retryCount, error, requestConfig) {
|
||||||
|
logger.warn(
|
||||||
|
{
|
||||||
|
retryCount,
|
||||||
|
name: error.name,
|
||||||
|
message: error.message,
|
||||||
|
code: error.code,
|
||||||
|
method: requestConfig.method,
|
||||||
|
baseURL: requestConfig.baseURL,
|
||||||
|
url: requestConfig.url,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
|
params: requestConfig.params,
|
||||||
|
data: error.response?.data,
|
||||||
|
},
|
||||||
|
'Retrying request after error',
|
||||||
|
);
|
||||||
|
},
|
||||||
...config,
|
...config,
|
||||||
});
|
});
|
||||||
return axiosInstance;
|
return axiosInstance;
|
||||||
|
|
Loading…
Reference in a new issue