How to get my Validator custom error message

i can’t get the custom error message i set in my validator, in stead console.log(error.message) displays :
Request failed with status code 403
instead of :
You are not allowed to do this

Here is the relevant validator code:

fails() {                                                                                                                                
    return this                                                                                                                                  
      .ctx                                                                                                                                       
      .response                                                                                                                                  
      .status(403)                                                                                                                               
      .json({                                                                                                                                    
        message: 'You are not allowed to do this'                                                                                                       
      })                                                                                                                                         
  }

i tried with cusom messages as the docs says but i get always the default error message Request failed with status code 403
how to get my custom error message on the client side?

1 Like

Can you share the full Validator code please?

It is an API server where I set the client headers with Accept: application/json. Here is the validator I declared for the corresponding route:

'use strict'

class StorePayment {
  
  get rules () {
    return {
      amount: "required"
    }
  }

  get messages() {
    return {
      'amount.required': 'You are not allowed to do this'
    }
  }

  async fails(errorMessages) {
    return this
      .ctx
      .response
      .status(403)
      .json({
        message: errorMessages[0].message
        // message: 'You are not allowed to do this' 
      })
  }
}

module.exports = StorePayment