Fix some error cases where a HTTP body might not be closed

This fixes two cases where error conditions could cause a registry response body not to be closed (found while looking into #2126).