Fixes bug 887593 - Make BadRequest raise an error message.

This is copying code over from ``middleware_app``, but I could not import without having a circular dependency. This code is depreciated anyway, so I'm not really concerned.