Skip to content

Commit

Permalink
Merge pull request #1290 from IntersectMBO/chore/1281-provide-more-lo…
Browse files Browse the repository at this point in the history
…gs-to-the-metadata-validation-service

chore(#1281): increase level of logs of metada validation service
  • Loading branch information
MSzalowski authored Jun 13, 2024
2 parents 561ae26 + e20ffea commit 27a9862
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
8 changes: 6 additions & 2 deletions govtool/metadata-validation/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { catchError, firstValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';
import * as blake from 'blakejs';

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

Expand All @@ -29,6 +29,9 @@ export class AppService {
}),
),
);

Logger.debug(LoggerMessage.METADATA_DATA, data);

if (standard && !noStandard) {
await validateMetadataStandard(data, standard);
}
Expand Down Expand Up @@ -56,6 +59,7 @@ export class AppService {
throw MetadataValidationStatus.INVALID_HASH;
}
} catch (error) {
Logger.error(LoggerMessage.METADATA_VALIDATION_ERROR, error);
if (Object.values(MetadataValidationStatus).includes(error)) {
status = error;
}
Expand Down
7 changes: 7 additions & 0 deletions govtool/metadata-validation/src/enums/LoggerMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum LoggerMessage {
METADATA_VALIDATION_ERROR = 'Metadata validation error',
METADATA_DATA = 'Metadata data',
CANNOT_GET_METADATA_URL = 'Cannot get metadata from URL',
PARSED_METADATA_BODY = 'Parsed metadata body',
CANNOT_PARSE_METADATA_BODY = 'Cannot parse metadata body',
}
1 change: 1 addition & 0 deletions govtool/metadata-validation/src/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './ValidationError';
export * from './LoggerMessage';
5 changes: 4 additions & 1 deletion govtool/metadata-validation/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true });
const app = await NestFactory.create(AppModule, {
cors: true,
logger: ['debug', 'error', 'log'],
});

const config = new DocumentBuilder()
.setTitle('Submission Tool')
Expand Down
9 changes: 9 additions & 0 deletions govtool/metadata-validation/src/utils/parseMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Logger } from '@nestjs/common';
import { LoggerMessage } from '@/enums';
import { MetadataStandard } from '@/types';

const CIP_108_VALUE_KEYS = ['abstract', 'motivation', 'rationale', 'title'];
Expand All @@ -20,6 +22,9 @@ export const parseMetadata = (
);
}
}
Logger.debug(LoggerMessage.PARSED_METADATA_BODY, parsedMetadata, {
standard,
});
return parsedMetadata;

case MetadataStandard.CIPQQQ:
Expand All @@ -33,8 +38,12 @@ export const parseMetadata = (
);
}
}
Logger.debug(LoggerMessage.PARSED_METADATA_BODY, parsedMetadata, {
standard,
});
return parsedMetadata;
default:
Logger.warn(LoggerMessage.CANNOT_PARSE_METADATA_BODY, { standard });
return;
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MetadataValidationStatus } from '@enums';
import { Logger } from '@nestjs/common';
import { LoggerMessage, MetadataValidationStatus } from '@enums';
import { cipStandardSchema } from '@schemas';
import { MetadataStandard } from '@types';

Expand All @@ -15,6 +16,7 @@ export const validateMetadataStandard = async (
try {
await cipStandardSchema[standard]?.validateAsync(data);
} catch (error) {
Logger.error(LoggerMessage.METADATA_VALIDATION_ERROR, error);
throw MetadataValidationStatus.INCORRECT_FORMAT;
}
};

0 comments on commit 27a9862

Please sign in to comment.