Skip to content
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

在serverless项目中,使用@midwayjs/validate中messages自定义错误信息时不生效 #3080

Open
Steppenwolf1900 opened this issue Jul 13, 2023 · 2 comments
Labels
status: Holding Same features may be hold, and implements layer.

Comments

@Steppenwolf1900
Copy link
Contributor

在serverless项目中,使用@midwayjs/validate中messages自定义错误信息时不生效,
dto代码如下:
image
使用messages自定义错误信息依旧按原来的信息返回
image

@czy88840616 czy88840616 added the status: Holding Same features may be hold, and implements layer. label Jul 14, 2023
@czy88840616
Copy link
Member

看文档,使用的是

export class UserDTO {
  @Rule(RuleType.number().required().error(new Error('my custom message')))
  id: number;
}

用的是 error,而不是 message。

@Steppenwolf1900
Copy link
Contributor Author

用error是可以自定义错误,但只能是针对这个属性不合法触发,并不知道是违反了哪个规则;
那比如这个示例,我想在每个不同规则不满足时,提示不同的自定义错误,如它的值不为字符串则提示不是字符串,如它的值长度超过24则提示最长长度不能超过24,我想实现这样的效果要怎么做,我看 joi 的官方是可以用 messages 来做的

export class Test {
  @Rule(
    RuleType.string().min(1).max(24).required().messages({
      'any.required': 'name必填',
    })
  )
  name: string;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: Holding Same features may be hold, and implements layer.
Development

No branches or pull requests

2 participants