Validator 4.0.9 fails with no messages


#1

Hi all,

Maybe my eyes are blind but I can’t see why this validation would fail.

The validation rules:

// Validate
            const rules = {
                title: 'required',
                price_int: 'required',
                area_int: 'required',
                type_id: 'required',
                lat: 'required',
                lon: 'required'
            }
            const validation = await validate(data, rules)

The data:

{
  title: 'E.057',
  rooms: 'T2',
  energy_certify: null,
  lat: 40.532997024774744,
  lon: -7.255825996398925,
  location: 'R. Francisco Sousa Tavares nº 1, Guarda, Guarda',
  url: null,
  area_int: '100',
  price_int: '1200000',
  rent_price_int: null,
  area_brute_int: 0,
  rooms_n: 0,
  garage: null,
  evalstatus: 0,
  dicofre: '090758',
  freguesia: 'Guarda',
  concelho: 'GUARDA',
  distrito: 'GUARDA',
  origin: 'cushman',
  condition: 3,
  margem: 10,
  yield: '4.500',
  type_id: '1',
  condition_id: '2',
  category_id: null
}

Validator version 4.0.9

Result:
Validation fails with empty messages from validation.messages()

Thanks


#2

How do you check that validation fails?


#3

Hello Virk,

Here is:

const validation = await validate(data, rules)
if (validation.fails()) {
  var errors = {}
  validation.messages().map(i => {
    errors[i.field] ? errors[i.field] : errors[i.field] = [];
    errors[i.field].push(i)
  })
  return response.send({success: false, error: 'Please check errors', errors: errors})
}

Does validation.fails() returns a Promise? Should I use await?

Thank you!


#4

Interesting, using validateAll() it works…

I see that it uses p-series, p-settle and p-lazy but could not debug deep enough to find where the problem is.