Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating storage blob container returns XML errors which cannot be parsed #7

Closed
invidian opened this issue Aug 22, 2019 · 1 comment

Comments

@invidian
Copy link

As a follow up to hashicorp/terraform-provider-azurerm#3939 and /hashicorp/terraform-provider-azurerm#3925. Currently when you use go-autorest and XML error is returned from Azure API, go-autorest fails to decode it, as it has hardcoded treating error messages as JSON:

I've tried some dummy fixes borrowed from https://github.com/Azure/azure-sdk-for-go/blob/master/storage/client.go#L977:

diff --git a/vendor/github.com/Azure/go-autorest/autorest/azure/azure.go b/vendor/github.com/Azure/go-autorest/autorest/azure/azure.go
index 3a0a439f..96f9a5ba 100644
--- a/vendor/github.com/Azure/go-autorest/autorest/azure/azure.go
+++ b/vendor/github.com/Azure/go-autorest/autorest/azure/azure.go
@@ -285,17 +285,24 @@ func WithErrorUnlessStatusCode(codes ...int) autorest.RespondDecorator {
                                var e RequestError
                                defer resp.Body.Close()
 
+                               var encodedAs autorest.EncodedAs
+                               if resp.Header.Get("Content-Type") == "application/xml" {
+                                       encodedAs = autorest.EncodedAsXML
+                               } else {
+                                       encodedAs = autorest.EncodedAsJSON
+                               }
+
                                // Copy and replace the Body in case it does not contain an error object.
                                // This will leave the Body available to the caller.
-                               b, decodeErr := autorest.CopyAndDecode(autorest.EncodedAsJSON, resp.Body, &e)
+                               b, decodeErr := autorest.CopyAndDecode(encodedAs, resp.Body, &e)

but apparently more code needs to be changed to get it working.

If this is not a proper place for this issue, feel free to move it to other repository or point me where I should create it.

@tombuildsstuff
Copy link
Owner

Fixed via Azure/go-autorest#465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants