You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While in the documentation it states that the body will return a JSON object if the body is set to an object, I found out that arrays also work the same way:
ctx.body=['foo','bar'];
This is awesome, but it might be a bug since in the code for that part the leftovers are treated as JSON:
Is this an intended feature? Everything that is not one of the above is just treated as JSON?
Notably in counter-intuitive examples, this will work and return a json {} with a status code 200 (I know about throw(), just pointing out this works not as expected and might be confusing):
app.use(ctx=>{ctx.body=newError('I work!');});
The text was updated successfully, but these errors were encountered:
we didn't bother guarding against everything a dev could put as a response body. returning a function simply doesn't make sense. returning a boolean could make sense. an error works, but it doesn't work as intended as some properties of an error are not enumerable.
personally, i would just add middleware in the app that asserts body types per app. the framework should remain minimal.
app.use(async(ctx,next)=>{awaitnext()ctx.assert.equal('object',typeofctx,500,'some dev did something wrong')})
this is only a few lines of code and could be tailored to each app
While in the documentation it states that the body will return a JSON object if the body is set to an object, I found out that arrays also work the same way:
This is awesome, but it might be a bug since in the code for that part the leftovers are treated as JSON:
Notably this makes other things work:
But some other things won't:
Is this an intended feature? Everything that is not one of the above is just treated as JSON?
Notably in counter-intuitive examples, this will work and return a json
{}
with a status code200
(I know aboutthrow()
, just pointing out this works not as expected and might be confusing):The text was updated successfully, but these errors were encountered: