SDK LRO Poller: Rest the result.HttpResponse.Body before returning #1124
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
longRunningOperationPoller.Poll
can return different poller errors, including:pollers.PollingFailedError
pollers.PollingCancelledError
These two errors contain a
HttpResponse
field and aMessage
field. As a consumer of this error type, one will likely read the body from theHttpResponse
, e.g., Azure Private Endpoint can return the following LRO responses:Both are retryable, though it is not a good idea to embed this retry logic in the
SDK
itself. It'd be better to do it per resource type. Therefore, accessing the latest response of the LRO, and inspect the error code shall be done.Currently, the
HttpResponse
is initially reset right after directly read in this function:go-azure-sdk/sdk/client/resourcemanager/poller_lro.go
Lines 130 to 138 in 774530e
While it is later consumed indirectly by the call below:
go-azure-sdk/sdk/client/resourcemanager/poller_lro.go
Lines 206 to 209 in 774530e
This PR resets the response back right after this function call.
Aside: It might be tempted to use the
LatestResponse()
method from the poller to get the latest response body. Unfortunately, the current implementation ofPollUntillDone
will set it to nil on error:go-azure-sdk/sdk/client/pollers/poller.go
Lines 208 to 210 in 774530e
Aside2: The
CreateOrUpdateThenPoll
method currently generated is not wrapping the poll error:go-azure-sdk/resource-manager/web/2023-12-01/domains/method_createorupdate.go
Lines 70 to 72 in 774530e
This makes users have no way to cast the error to any of the poller errors. The only workaround is to split the call to
CreateOrUpdate
+PollUntillDone
.Relating to hashicorp/terraform-provider-azurerm#21293