more robust handling of error responses