5

I have added validation rules on a model in loopback. Validations are working fine but the response message i get is somewhat automatically generated. I need to send a custom response object based on a validation.

My model validation is multiploof of 5 as below

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

I get validation message as below

{
  "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
        }
      }
    ]
  }
}

I need to modify the response object according to my requirement, Can i update this response object ?

TechChain
  • 8,404
  • 29
  • 103
  • 228

0 Answers0