New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(oneOf): add new error types #1022
feat(oneOf): add new error types #1022
Conversation
src/middlewares/one-of.ts
Outdated
@@ -9,16 +9,19 @@ const dummyItem: ContextItem = { async run() {} }; | |||
|
|||
export type OneOfCustomMessageBuilder = (options: { req: Request }) => any; | |||
|
|||
export type OneOfErrorType = 'grouped' | 'leastErroredOnly' | 'legacy'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about leastErroredOnly
name, any suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No better names yet...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the name grouped
as it describes well the behaviour.
What do you think of flat
instead of legacy
? It sounds exactly like the opposite of grouped
.
As for leastErroredOnly
... still no better ideas 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flat
sounds nice to me.
src/middlewares/one-of.ts
Outdated
@@ -9,16 +9,19 @@ const dummyItem: ContextItem = { async run() {} }; | |||
|
|||
export type OneOfCustomMessageBuilder = (options: { req: Request }) => any; | |||
|
|||
export type OneOfErrorType = 'grouped' | 'leastErroredOnly' | 'legacy'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No better names yet...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add docs too?
src/middlewares/one-of.ts
Outdated
@@ -9,16 +9,19 @@ const dummyItem: ContextItem = { async run() {} }; | |||
|
|||
export type OneOfCustomMessageBuilder = (options: { req: Request }) => any; | |||
|
|||
export type OneOfErrorType = 'grouped' | 'leastErroredOnly' | 'legacy'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the name grouped
as it describes well the behaviour.
What do you think of flat
instead of legacy
? It sounds exactly like the opposite of grouped
.
As for leastErroredOnly
... still no better ideas 😢
c71a8a5
to
540ead2
Compare
src/middlewares/one-of.ts
Outdated
message?: OneOfCustomMessageBuilder, | ||
options: { message: OneOfCustomMessageBuilder; errorType?: OneOfErrorType }, | ||
): Middleware & { run: (req: Request) => Promise<void> }; | ||
export function oneOf( | ||
chains: (ValidationChain | ValidationChain[])[], | ||
message?: any, | ||
options: { message?: any; errorType?: OneOfErrorType }, | ||
): Middleware & { run: (req: Request) => Promise<void> }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hoping that in the future typescript will help us to avoid these awful signatures.
540ead2
to
4b840c5
Compare
Merging this, we still have some time to update |
Description
This closes #956
We allow the user to choose between different error types:
grouped
: new default behaviour that groups the errors based on the original branches.legacy
: old behaviour that joins the errors from different branches togetherleastErroredOnly
: returns only the group with less errorsTo-do list