Skip to content

Commit 48993ad

Browse files
doug-wadedead-horse
authored andcommitted
docs: Document other body types (#1285)
1 parent acb388b commit 48993ad

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/api/response.md

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ so you can make a correction.
124124

125125
If `response.status` has not been set, Koa will automatically set the status to `200` or `204`.
126126

127+
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:
128+
129+
```
130+
app.use(async (ctx, next) => {
131+
await next()
132+
133+
ctx.assert.equal('object', typeof ctx, 500, 'some dev did something wrong')
134+
})
135+
```
136+
127137
#### String
128138

129139
The Content-Type is defaulted to text/html or text/plain, both with

0 commit comments

Comments
 (0)