Improve support for JSON formatted HTTP errors.
Cleanup code.