Propagate exception / test failures so that the correct status code is returned.

Fixes gh-2048 and fixes gh-2051