hapijs/hapi — pull request #2031 by voxpelli (2014-10-21 13:43:01+00:00)
Title: Guard against exceptions in request validation

**Observed in:**

hapi `6.11.1` and `7.0.0`

**Expected behavior:**

When an input or response validation plugin throws an error, it should result in a `500` error being returned.

**Observed behavior:**

Such an error now instead breaks the request life cycle, resulting in no response at all being sent and the request not being closed.

**Solution:**

Looking at how other steps in the request life cycle protects against thrown errors using `request._protect.run()` I adapted the plugin calls in the validators to utilize the same protection. That resulted in the expected behavior for me when an input or a response validator plugin threw an exception.

All tests pass with this addition, but there's some noise in the test output that comes from the logger in `Protect`. I also haven't added any new test cases that ensures that exceptions thrown in validator plugins are caught in this new way. If you think this approach looks good then I'll happily try to incorporate the changes into the test cases.