-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Customizing error messages #2146
Comments
Related to #1867 |
@jangeorgiev , is #1867 that @shadyanwar mentioned above something you're looking for? If yes, I'd like to continue the discussion over there instead. Thanks. |
No, it's not related to custom errors that are returned from HttpErrors.UnprocessableEntity(). |
@YaelGit might be relevant to you? |
Based on the issue description and the discussion, I see two incremental steps we can make:
Does it look like a reasonable plan to you? I don't think this will become a priority for us in the next 3-6 months, so it's up to you to contribute these improvements. I am happy to help you along the way if you decide so. See https://loopback.io/doc/en/contrib/code-contrib.html to get started. |
@bajtos I hope to find time next weekend to work on this. It would be nice if you tell me where to start. |
@shadyanwar that's great to hear! Here is the code converting AJV validation errors to an HttpError instance: |
@jangeorgiev, is this issue good to close? Thanks. |
Hey @dhmlau, thanks for asking. I updated my project to last version and I tried to use custom error messages as described in AJV Documentation, but it didn't worked. Thanks in advance. |
@jangeorgiev 😄 No problem! You have to install const localize = require('ajv-i18n');
export class MyApplication {
constructor() {
// ...
this.bind(RestBindings.REQUEST_BODY_PARSER_OPTIONS).to({
validation: {
ajvErrorTransformer: (errors: AJV.ErrorObject[]): AJV.ErrorObject[] => {
// `.zh()` is for Chinese, for other languages check here: https://github.com/epoberezkin/ajv-i18n#supported-locales
localize.zh(errors);
// Because the translation function is mutable, you have to return the original object.
return errors;
},
},
});
}
} |
Great! The example works perfect! Still I have no idea how to integrate Thanks for hard work guys ! |
Feature proposal
I have noticed that currently there are no way of customizing error messages returned from AJV in LB4.
I have found that there is implementation of handling error message already - AJV-Errors.
I'll be very happy to be able to customize error messages, because some of them are extremely ugly.
Example:
See code here
The code above in case of violation of patter will return
"should match pattern "^[a-z]+$""
The text was updated successfully, but these errors were encountered: