Make ctx.assert response in JSON

441 Views Asked by At

I have a few ctx.assert in my code, something like:

ctx.assert(db && fb && ObjectId, 400, 'Email validation config error')

If that assert fails, my response will be "Email validation config error" as string, but I would like to get a response in JSON, I tried something like that but it doesn't work:

ctx.assert(db && fb && ObjectId, 400, {error: 'Email validation config error'})

Is there a way to make the response from ctx.assert be in JSON?

1

There are 1 best solutions below

1
On BEST ANSWER
ctx.assert(db && fb && ObjectId, 400, JSON.stringify({error: 'Email validation config error'}))