Close response bodies on error

Also check JSON decoding errors.