From 354485dddd513af8bf5eb61101e792aa57939287 Mon Sep 17 00:00:00 2001 From: Doug Wade Date: Thu, 6 Dec 2018 21:24:23 -0800 Subject: [PATCH 1/2] [#965]: Document other body types --- docs/api/response.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/api/response.md b/docs/api/response.md index 602bc1487..bc3f20906 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 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 From 7f1236da827db5463fe43576947d8520b640c39b Mon Sep 17 00:00:00 2001 From: Martin Iwanowski Date: Sat, 8 Dec 2018 13:34:02 -0800 Subject: [PATCH 2/2] Update docs/api/response.md Co-Authored-By: doug-wade --- docs/api/response.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/response.md b/docs/api/response.md index bc3f20906..17be05191 100644 --- a/docs/api/response.md +++ b/docs/api/response.md @@ -124,7 +124,7 @@ 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 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: +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) => {