Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hospital-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Roshan Suvarnkar
hospital-service
Commits
9d96059a
Commit
9d96059a
authored
1 month ago
by
roshan
Browse files
Options
Downloads
Patches
Plain Diff
change in main to support validation error
parent
a8d6c360
No related branches found
No related tags found
No related merge requests found
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
package-lock.json
+0
-16730
0 additions, 16730 deletions
package-lock.json
src/main.ts
+20
-41
20 additions, 41 deletions
src/main.ts
with
20 additions
and
16771 deletions
package-lock.json
deleted
100644 → 0
+
0
−
16730
View file @
a8d6c360
This diff is collapsed.
Click to expand it.
src/main.ts
+
20
−
41
View file @
9d96059a
...
...
@@ -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
);
},
}),
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment