Skip to content

Commit

Permalink
Merge pull request #2231 from IntersectMBO/test
Browse files Browse the repository at this point in the history
fix: validation request cancelation
  • Loading branch information
MSzalowski authored Oct 24, 2024
2 parents d37f69b + c80d37d commit 9ba0935
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 13 additions & 2 deletions govtool/metadata-validation/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';
import { ConfigModule } from '@nestjs/config';
import * as http from 'http';
import * as https from 'https';

import { AppController } from './app.controller';
import { AppService } from './app.service';
Expand All @@ -12,8 +14,17 @@ import { HealthModule } from './health/health.module';
isGlobal: true,
}),
HttpModule.register({
timeout: 5000,
maxRedirects: 5,
timeout: 10000,
maxContentLength: 10 * 1024 * 1024, // Max content length 10MB
maxBodyLength: 10 * 1024 * 1024, // Max body length 10MB
responseType: 'text',
headers: {
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: '0',
},
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
}),
HealthModule,
],
Expand Down
17 changes: 5 additions & 12 deletions govtool/metadata-validation/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { Injectable, Logger } from '@nestjs/common';
import { catchError, firstValueFrom, timeout } from 'rxjs';
import { catchError, finalize, firstValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';
import * as blake from 'blakejs';
import { AxiosRequestConfig } from 'axios';
import * as jsonld from 'jsonld';

import { ValidateMetadataDTO } from '@dto';
import { LoggerMessage, MetadataValidationStatus } from '@enums';
import { validateMetadataStandard, parseMetadata, getStandard } from '@utils';
import { ValidateMetadataResult } from '@types';

const axiosConfig: AxiosRequestConfig = {
timeout: 5000,
maxContentLength: 10 * 1024 * 1024, // Max content length 10MB
maxBodyLength: 10 * 1024 * 1024, // Max body length 10MB
responseType: 'text',
};

@Injectable()
export class AppService {
constructor(private readonly httpService: HttpService) {}
Expand All @@ -30,9 +22,10 @@ export class AppService {

try {
const { data: rawData } = await firstValueFrom(
this.httpService.get(url, axiosConfig).pipe(
timeout(5000),
catchError(() => {
this.httpService.get(url).pipe(
finalize(() => Logger.log(`Fetching ${url} completed`)),
catchError((error) => {
Logger.error(error, JSON.stringify(error));
throw MetadataValidationStatus.URL_NOT_FOUND;
}),
),
Expand Down

0 comments on commit 9ba0935

Please sign in to comment.