...
1
2
3 package management
4
5
6
7
8 import (
9 "encoding/xml"
10 "fmt"
11 )
12
13
14
15 type AzureError struct {
16 Code string
17 Message string
18 }
19
20
21 func (e AzureError) Error() string {
22 return fmt.Sprintf("Error response from Azure. Code: %s, Message: %s", e.Code, e.Message)
23 }
24
25
26
27 func IsResourceNotFoundError(err error) bool {
28 azureErr, ok := err.(AzureError)
29 return ok && azureErr.Code == "ResourceNotFound"
30 }
31
32
33 func getAzureError(responseBody []byte) error {
34 var azErr AzureError
35 err := xml.Unmarshal(responseBody, &azErr)
36 if err != nil {
37 return fmt.Errorf("Failed parsing contents to AzureError format: %v", err)
38 }
39 return azErr
40
41 }
42
View as plain text