Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add any request support #167

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "1.2.2",
"version": "1.2.3",
"packages": [
"packages/*"
],
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/elastic/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions packages/http/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
}
39 changes: 39 additions & 0 deletions packages/http/src/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,44 @@ export class ApiService {
}
}

async request(requestConfig: AxiosRequestConfig, errorHandler?: (error: any) => Promise<boolean>): Promise<any> {
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<boolean>): Promise<any> {
const profiler = new PerformanceProfiler();
try {
Expand Down Expand Up @@ -254,6 +292,7 @@ export class ApiService {
}
}


private getHostname(url: string): string {
return new URL(url).hostname;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/monitoring/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/rabbitmq/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/redis/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down