Add support for error responses in JSON format (closes #113)

Thanks to @andreif for the patch and tests