Wrap some cases where exceptions can be thrown.

This fixes a few cases where the front-end expects a JSON response, but we don't deliver one.