422 validation response code

#1

Hi,

How do I set a failed route validation to return a 422 response code?

Many thanks.

0 Likes

#2

Hello @jacksoncharles, do you want to send this as a json response?
If so, then you can use the response.status(422).json(data) function to achieve this.

0 Likes

#3

Thanks for that, yes it’s a JSON response. But I have route validation and the response is being automatically handled. My routes file simply reads

	Route
		.post('/pick-jobs', 'PickJobs/PostPickJobController.action')
		.validator('PostPickJob')
		.as('postpickjob')

And I have a simple validator class. Any ideas?

0 Likes

#4

Look into an exception handler. See docs.

0 Likes