From d141239a2204149577b9d51d51c29a8662e2875a Mon Sep 17 00:00:00 2001 From: Conicaw Date: Sat, 23 Dec 2023 21:43:50 -0600 Subject: [PATCH] feat: log retries Log retries commit-id:2346ea7d --- lib/http.module.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/http.module.ts b/lib/http.module.ts index a9ab1be..7fbb8e6 100644 --- a/lib/http.module.ts +++ b/lib/http.module.ts @@ -1,5 +1,5 @@ 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 axios from 'axios'; import axiosRetry, { exponentialDelay } from 'axios-retry'; @@ -13,10 +13,28 @@ import type { } from './interfaces'; const createAxiosInstance = (config?: HttpModuleOptions) => { + const logger = new Logger(HttpService.name); const axiosInstance = axios.create(config); axiosRetry(axiosInstance, { // Default exponential backoff 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, }); return axiosInstance;