yahoo/mojito — pull request #1286 by gomezd (2013-11-13 21:26:22+00:00)
Title: Handle invalid context exceptions with output handler

The `validateContext` method of the resource store throws exceptions for invalid contexts, however the dispatcher doesn't handle these exceptions and the app crashes.

```
Error: INVALID dimension key "foo"
at RSAddonSuperBundle.Y.extend.validateContext (/git-data/common/utils/mojito-dimensions-base/addons/rs/super-bundle.server.js:198:33)
at ResourceStore. (/git-data/apps/search-apps-news/node_modules/mojito/node_modules/yui/oop/oop-min.js:1:2230)
at i.Method.exec (/git-data/apps/search-apps-news/node_modules/mojito/node_modules/yui/event-custom-base/event-custom-base-min.js:1:1161)
at ResourceStore.o.(anonymous function).r.(anonymous function) [as validateContext] (/git-data/apps/search-apps-news/node_modules/mojito/node_modules/yui/event-custom-base/event-custom-base-min.js:1:616)
at Object.Y.namespace.Dispatcher.dispatch (/git-data/apps/search-apps-news/node_modules/mojito/lib/app/autoload/dispatch.server.js:125:19)
at Object.dispatcher [as handle] (/git-data/apps/search-apps-news/node_modules/mojito/lib/mojito.js:363:41)
at next (/git-data/apps/search-apps-news/node_modules/mojito/node_modules/express/node_modules/connect/lib/http.js:204:15)
at Object.handle (/git-data/apps/search-apps-news/node_modules/mojito/lib/app/middleware/mojito-router.js:101:13)
at next (/git-data/apps/search-apps-news/node_modules/mojito/node_modules/express/node_modules/connect/lib/http.js:204:15)
at run (/git-data/apps/search-apps-news/node_modules/mojito/lib/app/middleware/mojito-handler-tunnel.js:34:24)

//client sees this
Internal Server Error
```

With this small change the dispatcher handles gracefully invalid context errors, and gives users the ability to implement their own version of validateContext and throw custom errors, in our case some context dimensions would result in a "Bad request" 400 error instead of the default 500.

Instead of crashing we would get:
```
error: (outputhandler.server): { [Error: INVALID dimension key "foo"] code: 400 }
info: (outputhandler.server): done

// client sees this
Error: 400

Error details are not available.
```