Skip to content

Commit 9160a09

Browse files
authored
Merge pull request #2232 from IntersectMBO/staging
fix: validation request cancelation
2 parents 38c1f41 + 9ba0935 commit 9160a09

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

govtool/metadata-validation/src/app.module.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Module } from '@nestjs/common';
22
import { HttpModule } from '@nestjs/axios';
33
import { ConfigModule } from '@nestjs/config';
4+
import * as http from 'http';
5+
import * as https from 'https';
46

57
import { AppController } from './app.controller';
68
import { AppService } from './app.service';
@@ -12,8 +14,17 @@ import { HealthModule } from './health/health.module';
1214
isGlobal: true,
1315
}),
1416
HttpModule.register({
15-
timeout: 5000,
16-
maxRedirects: 5,
17+
timeout: 10000,
18+
maxContentLength: 10 * 1024 * 1024, // Max content length 10MB
19+
maxBodyLength: 10 * 1024 * 1024, // Max body length 10MB
20+
responseType: 'text',
21+
headers: {
22+
'Cache-Control': 'no-cache',
23+
Pragma: 'no-cache',
24+
Expires: '0',
25+
},
26+
httpAgent: new http.Agent({ keepAlive: true }),
27+
httpsAgent: new https.Agent({ keepAlive: true }),
1728
}),
1829
HealthModule,
1930
],

govtool/metadata-validation/src/app.service.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import { Injectable, Logger } from '@nestjs/common';
2-
import { catchError, firstValueFrom, timeout } from 'rxjs';
2+
import { catchError, finalize, firstValueFrom } from 'rxjs';
33
import { HttpService } from '@nestjs/axios';
44
import * as blake from 'blakejs';
5-
import { AxiosRequestConfig } from 'axios';
65
import * as jsonld from 'jsonld';
76

87
import { ValidateMetadataDTO } from '@dto';
98
import { LoggerMessage, MetadataValidationStatus } from '@enums';
109
import { validateMetadataStandard, parseMetadata, getStandard } from '@utils';
1110
import { ValidateMetadataResult } from '@types';
1211

13-
const axiosConfig: AxiosRequestConfig = {
14-
timeout: 5000,
15-
maxContentLength: 10 * 1024 * 1024, // Max content length 10MB
16-
maxBodyLength: 10 * 1024 * 1024, // Max body length 10MB
17-
responseType: 'text',
18-
};
19-
2012
@Injectable()
2113
export class AppService {
2214
constructor(private readonly httpService: HttpService) {}
@@ -30,9 +22,10 @@ export class AppService {
3022

3123
try {
3224
const { data: rawData } = await firstValueFrom(
33-
this.httpService.get(url, axiosConfig).pipe(
34-
timeout(5000),
35-
catchError(() => {
25+
this.httpService.get(url).pipe(
26+
finalize(() => Logger.log(`Fetching ${url} completed`)),
27+
catchError((error) => {
28+
Logger.error(error, JSON.stringify(error));
3629
throw MetadataValidationStatus.URL_NOT_FOUND;
3730
}),
3831
),

0 commit comments

Comments
 (0)