Response status always says 404

I created a new policy to inspect the ctx object. Everything seems ok, except for ctx.status which always returns 404. The strapi logs say 200 that’s why I don’t understand what’s going on

Code:
app/config/policies/ctx.js:

module.exports = async (ctx, next) => {
  console.log('@@ method', ctx.request.method) // ok
  console.log('@@ ctx request', ctx.request) // ok
  console.log('@@ ctx status', ctx.status) // always 404

  return await next()
}

The default for koa is to set that to 404, since it’s executed before the return await next() it will be that way. If you add another one after the await next() (and remove the return) you should see it change.

Try this:

module.exports = async (ctx, next) => {
  console.log('@@ method', ctx.request.method) // ok
  console.log('@@ ctx request', ctx.request) // ok
  console.log('@@ ctx status', ctx.status) // always 404

  await next()

  console.log('@@ ctx status', ctx.status)
}
2 Likes