From 48993ade9b0831fbce28d94b3b0963a4b0dccbdd Mon Sep 17 00:00:00 2001 From: Douglas Wade Date: Tue, 11 Dec 2018 20:33:36 -0800 Subject: [PATCH] docs: Document other body types (#1285) --- docs/api/response.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/api/response.md b/docs/api/response.md index bdea105..ac6c93e 100644 --- a/docs/api/response.md +++ b/docs/api/response.md @@ -124,6 +124,16 @@ so you can make a correction. If `response.status` has not been set, Koa will automatically set the status to `200` or `204`. +Koa doesn't guard against everything that could be put as a response body -- a function doesn't serialise meaningfully, returning a boolean may make sense based on your application, and while an error works, it may not work as intended as some properties of an error are not enumerable. We recommend adding middleware in your app that asserts body types per app. A sample middleware might be: + +``` +app.use(async (ctx, next) => { + await next() + + ctx.assert.equal('object', typeof ctx, 500, 'some dev did something wrong') +}) +``` + #### String The Content-Type is defaulted to text/html or text/plain, both with