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
fix(schema): fix custom error message set through .Error() nested decorator #2699
base: production
Are you sure you want to change the base?
Conversation
0eb4730
to
9384b6a
Compare
0f9654d
to
4fef967
Compare
Benchmarks
ExplanationThe benchmark shows a performance difference between the frameworks. We note that Ts.ED is often last. In fact, Ts.ED uses features useful to a production application which reduce its performance. For example, Ts.ED initializes a sandbox (async_hook) for each request in order to work in an isolated context if necessary. All this at a necessary cost that reflects the reality of a production application ;) |
Benchmarks
ExplanationThe benchmark shows a performance difference between the frameworks. We note that Ts.ED is often last. In fact, Ts.ED uses features useful to a production application which reduce its performance. For example, Ts.ED initializes a sandbox (async_hook) for each request in order to work in an isolated context if necessary. All this at a necessary cost that reflects the reality of a production application ;) |
@ktalebian Can review this PR. I need your review over the AJV response error ;) |
4fef967
to
b9e1b87
Compare
Benchmarks
ExplanationThe benchmark shows a performance difference between the frameworks. We note that Ts.ED is often last. In fact, Ts.ED uses features useful to a production application which reduce its performance. For example, Ts.ED initializes a sandbox (async_hook) for each request in order to work in an isolated context if necessary. All this at a necessary cost that reflects the reality of a production application ;) |
emUsed: true, | ||
instancePath: "/word", | ||
keyword: "minLength", | ||
message: "must NOT have fewer than 10 characters", |
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.
Will this always remain the default error message? Shouldn't this also say Title must be at least 10 characters long
?
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.
What would happen if you have
class Model {
@MinLength(10).Error("Title must be at least 10 characters long")
word: string;
@MinLength(100).Error("Setence must be at least 100 characters long")
sentence: string;
}
The response would have a single message
but the params.errors
would then have two entries.
I feel the result.message
should actually be the @DefaultMessage
decorator that sits on Model
class, not the individual schemaPath error.
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.
Ajv-errors doesn't override the default message. it wrap the original error and add his message.
Look this page, there is all explanation:
https://ajv.js.org/packages/ajv-errors.html
I feel the result.message should actually be the @DefaultMessage decorator that sits on Model class, not the individual schemaPath error.
This is not the current test @ktalebian ^^. DefaultMsg decorator should works, if there is no other message that match the properties + rules.
Furthermore, I don't really have control over how the error message came out. Ajv-errors manages everything and I just follow what is indicated in their docs in order to have the expected behavior.
If we really want to have better message management, we would have to write the plugin ourselves to overload the error messages. I clearly don't have the time to do this nor the desire. This module won't be useful to me in a project, because I don't use these error messages in a front-end project.
But if you have time, you can do develop the module. Instead of adding custom keyword (like is do by ajv-errors), the solution could be to override the errors after the validation is done (by matching error.instancePath + errro.keyword).
See you
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.
@ktalebian is it ok for you ? (but we haven't a lot of choices XD)
Closes: #2696
Information
Todos