Skip to content
Snippets Groups Projects
Commit 9d96059a authored by roshan's avatar roshan
Browse files

change in main to support validation error

parent a8d6c360
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -21,6 +21,7 @@ import {
setPiiFields,
AppException,
fetchAllSecretsAndWriteEnv,
formatValidationErrors,
} from 'nest-common-utilities';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { config } from './config/pii.config';
......@@ -54,23 +55,12 @@ async function bootstrap(): Promise<void> {
app.useGlobalPipes(
new ValidationPipe({
whitelist: true, // strip unknown fields
forbidNonWhitelisted: true, // throw error on unknown fields
transform: true, // auto-transform payloads to DTOs
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
exceptionFactory: (errors) => {
const messages = errors.flatMap((err) =>
Object.values(err.constraints || {}).map((msg) => ({
key: err.property,
message: msg,
})),
);
const combinedMessage = messages.map((m) =>
`${m.key}: ${m.message}`,
).join(', ');
return new AppException(
combinedMessage || 'Validation failed',
'VALIDATION_ERROR',
);
const formatted = formatValidationErrors(errors);
return new AppException(formatted || 'Validation failed', 979);
},
}),
);
......@@ -106,19 +96,8 @@ async function bootstrap(): Promise<void> {
forbidNonWhitelisted: true, // throw error on unknown fields
transform: true, // auto-transform payloads to DTOs
exceptionFactory: (errors) => {
const messages = errors.flatMap((err) =>
Object.values(err.constraints || {}).map((msg) => ({
key: err.property,
message: msg,
})),
);
const combinedMessage = messages.map((m) =>
`${m.key}: ${m.message}`,
).join(', ');
return new AppException(
combinedMessage || 'Validation failed',
'VALIDATION_ERROR',
);
const formatted = formatValidationErrors(errors);
return new AppException(formatted || 'Validation failed', 979);
},
}),
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment