diff --git a/README.md b/README.md index 89bcc9e..2fdee61 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ nestjs module that just doing little modification to the original and good **nes ## features - * axios - the most used package for http requests in npm. + * axios - the most used package for http requests in npm and the one used by nestjs official http library. + * better axios stack trace - axios has an [open issue](https://github.com/axios/axios/issues/2387) about improvement of their stack trace. + in this library there is a default interceptor that will intercept the stack trace and will add data to it. * promise based - most of us using the current http module that uses observable which we don't use most of the time and in order to avoid it were just calling `.toPromise()` every http call. * retries - in many cases we will want to retry a failing http call. @@ -73,7 +75,8 @@ import { HttpModule } from 'nestjs-http-promise' ``` ### default configuration - just the default config of axios-retry : https://github.com/softonic/axios-retry#options + * default config of axios-retry : https://github.com/softonic/axios-retry#options + * better axios stack trace is added by default, you can turn it off by passing the **isBetterStackTraceEnabled** to false. ## async configuration When you need to pass module options asynchronously instead of statically, use the `registerAsync()` method **just like in nest httpModule**. diff --git a/lib/http.module.ts b/lib/http.module.ts index 7827b19..f85ecdb 100644 --- a/lib/http.module.ts +++ b/lib/http.module.ts @@ -13,10 +13,14 @@ import { HttpModuleOptionsFactory, } from './interfaces'; import axiosRetry from 'axios-retry'; +import axiosBetterStacktrace from 'axios-better-stacktrace'; -const createAxiosRetry = (config?: HttpModuleOptions) => { +const createAxiosInstance = (config?: HttpModuleOptions) => { const axiosInstance = Axios.create(config); axiosRetry(axiosInstance, config); + if(config.isBetterStackTraceEnabled === undefined || config.isBetterStackTraceEnabled) { + axiosBetterStacktrace(axiosInstance); + } return axiosInstance; } @@ -25,7 +29,7 @@ const createAxiosRetry = (config?: HttpModuleOptions) => { HttpService, { provide: AXIOS_INSTANCE_TOKEN, - useValue: createAxiosRetry(), + useValue: createAxiosInstance(), }, ], exports: [HttpService], @@ -37,7 +41,7 @@ export class HttpModule { providers: [ { provide: AXIOS_INSTANCE_TOKEN, - useValue: createAxiosRetry(config), + useValue: createAxiosInstance(config), }, { provide: HTTP_MODULE_ID, @@ -55,7 +59,7 @@ export class HttpModule { ...this.createAsyncProviders(options), { provide: AXIOS_INSTANCE_TOKEN, - useFactory: (config: HttpModuleOptions) => createAxiosRetry(config), + useFactory: (config: HttpModuleOptions) => createAxiosInstance(config), inject: [HTTP_MODULE_OPTIONS], }, { diff --git a/lib/interfaces/http-module.interface.ts b/lib/interfaces/http-module.interface.ts index 1eee6f4..3875a3f 100644 --- a/lib/interfaces/http-module.interface.ts +++ b/lib/interfaces/http-module.interface.ts @@ -2,7 +2,7 @@ import { ModuleMetadata, Provider, Type } from '@nestjs/common'; import { AxiosRequestConfig } from 'axios'; import { IAxiosRetryConfig } from 'axios-retry' -export type HttpModuleOptions = (AxiosRequestConfig & IAxiosRetryConfig); +export type HttpModuleOptions = (AxiosRequestConfig & IAxiosRetryConfig & { isBetterStackTraceEnabled?: boolean }); export interface HttpModuleOptionsFactory { createHttpOptions(): Promise | HttpModuleOptions; diff --git a/package-lock.json b/package-lock.json index 13792fd..008d0cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nestjs-http-promise", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -486,7 +486,8 @@ "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true }, "ansi-styles": { "version": "4.3.0", @@ -562,6 +563,11 @@ "follow-redirects": "^1.14.4" } }, + "axios-better-stacktrace": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/axios-better-stacktrace/-/axios-better-stacktrace-2.1.2.tgz", + "integrity": "sha512-/ikpK5W7UhCAdl9pQss1vpTfLtOQpbv8edRZ2a9wWSux2dnGmqjVHkFsMKnyllysxm046C016lqGjUgGNECcag==" + }, "axios-retry": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/axios-retry/-/axios-retry-3.2.4.tgz", diff --git a/package.json b/package.json index 880aa0c..da41585 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ }, "dependencies": { "axios": "~0.24.0", + "axios-better-stacktrace": "^2.1.2", "axios-retry": "^3.2.4" }, "devDependencies": {