diff --git a/lerna.json b/lerna.json index 6a28cb72..26e7d48b 100644 --- a/lerna.json +++ b/lerna.json @@ -1,7 +1,7 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useWorkspaces": true, - "version": "1.2.2", + "version": "1.2.3", "packages": [ "packages/*" ], diff --git a/package-lock.json b/package-lock.json index 4edc0a4e..9bcda812 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14117,7 +14117,7 @@ }, "packages/auth": { "name": "@multiversx/sdk-nestjs-auth", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "dependencies": { "@multiversx/sdk-core": "*", @@ -14250,7 +14250,7 @@ }, "packages/cache": { "name": "@multiversx/sdk-nestjs-cache", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "dependencies": { "lru-cache": "^8.0.4", @@ -14308,7 +14308,7 @@ }, "packages/common": { "name": "@multiversx/sdk-nestjs-common", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "dependencies": { "@multiversx/sdk-core": "^11.4.1", @@ -14341,7 +14341,7 @@ }, "packages/elastic": { "name": "@multiversx/sdk-nestjs-elastic", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.12.0", @@ -14356,7 +14356,7 @@ }, "packages/http": { "name": "@multiversx/sdk-nestjs-http", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "dependencies": { "agentkeepalive": "^4.3.0", @@ -14386,7 +14386,7 @@ }, "packages/monitoring": { "name": "@multiversx/sdk-nestjs-monitoring", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "dependencies": { "prom-client": "^14.0.1", @@ -14405,7 +14405,7 @@ }, "packages/rabbitmq": { "name": "@multiversx/sdk-nestjs-rabbitmq", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "dependencies": { "@golevelup/nestjs-rabbitmq": "^3.0.0", @@ -14426,7 +14426,7 @@ }, "packages/redis": { "name": "@multiversx/sdk-nestjs-redis", - "version": "1.2.2", + "version": "1.2.3", "license": "GPL-3.0-or-later", "dependencies": { "ioredis": "^5.2.3" diff --git a/packages/auth/package.json b/packages/auth/package.json index ba78522f..48c719c8 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-auth", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs auth package", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/cache/package.json b/packages/cache/package.json index 60c38c29..e49aac86 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-cache", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs cache package", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/common/package.json b/packages/common/package.json index f3260d84..b5f334b6 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-common", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs common package", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/elastic/package.json b/packages/elastic/package.json index 4f7460fd..62e375e1 100644 --- a/packages/elastic/package.json +++ b/packages/elastic/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-elastic", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs elastic package", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/http/package.json b/packages/http/package.json index 78a1f377..cac60c56 100644 --- a/packages/http/package.json +++ b/packages/http/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-http", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs http package", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -33,15 +33,15 @@ "typescript": "^4.3.5" }, "dependencies": { - "agentkeepalive": "^4.3.0", - "axios": "^0.27.2" + "agentkeepalive": "^4.3.0" }, "peerDependencies": { "@multiversx/sdk-nestjs-common": "*", "@multiversx/sdk-nestjs-monitoring": "*", - "@nestjs/common": "^9.x" + "@nestjs/common": "^9.x", + "axios": "*" }, "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/http/src/api/api.service.ts b/packages/http/src/api/api.service.ts index 00537c4b..d43172ae 100644 --- a/packages/http/src/api/api.service.ts +++ b/packages/http/src/api/api.service.ts @@ -196,6 +196,44 @@ export class ApiService { } } + async request(requestConfig: AxiosRequestConfig, errorHandler?: (error: any) => Promise): Promise { + const settings = new ApiSettings(); + + const profiler = new PerformanceProfiler(); + try { + const config = await this.getConfig(settings); + + if (!requestConfig.headers) { + requestConfig.headers = {}; + } + + requestConfig.headers = { ...config.headers, ...requestConfig.headers }; + requestConfig.httpAgent = config.httpAgent; + requestConfig.timeout = config.timeout; + requestConfig.transformResponse = config.transformResponse; + + const response = await axios.request(requestConfig); + return response; + } catch (error: any) { + let handled = false; + if (errorHandler) { + handled = await errorHandler(error); + } + + if (!handled) { + const customError = this.getCustomError('REQUEST', requestConfig.url || '', requestConfig.data, error); + + const logger = new Logger(ApiService.name); + logger.error(customError); + + throw customError; + } + } finally { + profiler.stop(); + this.metricsService.setExternalCall(this.getHostname(requestConfig.baseURL as string), profiler.duration); + } + } + async delete(url: string, data: any, settings: ApiSettings = new ApiSettings(), errorHandler?: (error: any) => Promise): Promise { const profiler = new PerformanceProfiler(); try { @@ -254,6 +292,7 @@ export class ApiService { } } + private getHostname(url: string): string { return new URL(url).hostname; } diff --git a/packages/monitoring/package.json b/packages/monitoring/package.json index 432bed01..54315368 100644 --- a/packages/monitoring/package.json +++ b/packages/monitoring/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-monitoring", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs monitoring package", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/rabbitmq/package.json b/packages/rabbitmq/package.json index e4922db6..850e8cd6 100644 --- a/packages/rabbitmq/package.json +++ b/packages/rabbitmq/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-rabbitmq", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs rabbitmq client package", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/redis/package.json b/packages/redis/package.json index 8afd11c3..532d61b0 100644 --- a/packages/redis/package.json +++ b/packages/redis/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-nestjs-redis", - "version": "1.2.2", + "version": "1.2.3", "description": "Multiversx SDK Nestjs redis client package", "main": "lib/index.js", "types": "lib/index.d.ts",