Add recovery handler which outputs JSON

Also add tests for error documents.