Reputation: 3209
I am trying to send a json response back to the application with a status code. This what I tired but didn't work.
if (validation.fails()) {
console.log(validation.messages())
return response.json(validation.messages(),false,401)
// or return response.json(validation.messages(),401)
// It always sends 200 status code
}
Upvotes: 2
Views: 2938
Reputation: 1760
One better solution is to use descriptive methods: https://adonisjs.com/docs/4.1/response#_descriptive_methods
Example:
response.unauthorized('Login First')
Upvotes: 0
Reputation: 3209
Found the solution. I need to use like this return response.status(401).json(validation.messages())
Upvotes: 2