diff --git a/govtool/metadata-validation/src/app.service.ts b/govtool/metadata-validation/src/app.service.ts index d15499582..633d77f2a 100644 --- a/govtool/metadata-validation/src/app.service.ts +++ b/govtool/metadata-validation/src/app.service.ts @@ -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'; @@ -29,6 +29,9 @@ export class AppService { }), ), ); + + Logger.debug(LoggerMessage.METADATA_DATA, data); + if (standard && !noStandard) { await validateMetadataStandard(data, standard); } @@ -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; } diff --git a/govtool/metadata-validation/src/enums/LoggerMessage.ts b/govtool/metadata-validation/src/enums/LoggerMessage.ts new file mode 100644 index 000000000..2984f7d7f --- /dev/null +++ b/govtool/metadata-validation/src/enums/LoggerMessage.ts @@ -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', +} diff --git a/govtool/metadata-validation/src/enums/index.ts b/govtool/metadata-validation/src/enums/index.ts index 118d3701d..3adce9a41 100644 --- a/govtool/metadata-validation/src/enums/index.ts +++ b/govtool/metadata-validation/src/enums/index.ts @@ -1 +1,2 @@ export * from './ValidationError'; +export * from './LoggerMessage'; diff --git a/govtool/metadata-validation/src/main.ts b/govtool/metadata-validation/src/main.ts index 213e7e7a1..052a4c8bb 100644 --- a/govtool/metadata-validation/src/main.ts +++ b/govtool/metadata-validation/src/main.ts @@ -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') diff --git a/govtool/metadata-validation/src/utils/parseMetadata.ts b/govtool/metadata-validation/src/utils/parseMetadata.ts index afa42e6b8..0669d13e1 100644 --- a/govtool/metadata-validation/src/utils/parseMetadata.ts +++ b/govtool/metadata-validation/src/utils/parseMetadata.ts @@ -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']; @@ -20,6 +22,9 @@ export const parseMetadata = ( ); } } + Logger.debug(LoggerMessage.PARSED_METADATA_BODY, parsedMetadata, { + standard, + }); return parsedMetadata; case MetadataStandard.CIPQQQ: @@ -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; } }; diff --git a/govtool/metadata-validation/src/utils/validateMetadataStandard.ts b/govtool/metadata-validation/src/utils/validateMetadataStandard.ts index 702027769..b2b285de2 100644 --- a/govtool/metadata-validation/src/utils/validateMetadataStandard.ts +++ b/govtool/metadata-validation/src/utils/validateMetadataStandard.ts @@ -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'; @@ -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; } };