Loopback4中的自定义验证响应对象?

问题描述 投票:2回答:1

我已在环回模型中添加了验证规则。验证工作正常,但我得到的响应消息会自动生成。我需要基于验证发送自定义响应对象。

我的模型验证是下面的5的多重证明

 @property({
    name: 'name',
    description: "The product's common name.",
    type: 'number',
    required: true,
    // Specify the JSON validation rules here
    jsonSchema: {
      multipleOf: 5
    },
  })
  counter: number;

我收到如下确认消息

{
  "error": {
    "statusCode": 422,
    "name": "UnprocessableEntityError",
    "message": "The request body is invalid. See error object `details` property for more info.",
    "code": "VALIDATION_FAILED",
    "details": [
      {
        "path": ".counter",
        "code": "multipleOf",
        "message": "should be multiple of 5",
        "info": {
          "multipleOf": 5
        }
      }
    ]
  }
}

我需要根据我的要求修改响应对象,我可以更新此响应对象吗?

typescript loopbackjs loopback loopback4
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.