0

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?

Fabio Sousa
  • 261
  • 1
  • 2
  • 11

1 Answers1

2
ctx.assert(db && fb && ObjectId, 400, JSON.stringify({error: 'Email validation config error'}))
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Tyler2P Aug 07 '21 at 08:47