koajs/koa — pull request #163 by jonathanong (2013-12-30 06:31:13+00:00)
Title: better 404 handling

just realized our current 404 handling is terrible. right now you have to do `if (this.status != 200 || this.body != null)`, which is really annoying and doesn't make sense at all.

you now have to set `this.status` now, but setting `.body =` will automatically set the status code to `200` if not already set. so now you can just do `if (!this.status)` to check whether has been "handled".

this is a backwards compatibility breaking change but IMO makes much more sense. this also drops support for `this.res.statusCode = `.

now, a 404 handler will look like this:

```js
app.use(function* pagenotfound(next){
yield next;
if (this.status) return;
this.body = 'page not found';
})
```

which makes much more sense than the monstrosity we had before.

i just fixed the tests so that it works. i'll add more if you're okay with it.