8
// AzureError represents an error returned by the management API. It has an error
9
// code (for example, ResourceNotFound) and a descriptive message.
10
type AzureError struct {
15
//Error implements the error interface for the AzureError type.
16
func (e AzureError) Error() string {
17
return fmt.Sprintf("Error response from Azure. Code: %s, Message: %s", e.Code, e.Message)
20
// IsResourceNotFoundError returns true if the provided error is an AzureError
21
// reporting that a given resource has not been found.
22
func IsResourceNotFoundError(err error) bool {
23
azureErr, ok := err.(AzureError)
24
return ok && azureErr.Code == "ResourceNotFound"
27
// getAzureError converts an error response body into an AzureError instance.
28
func getAzureError(responseBody []byte) error {
30
err := xml.Unmarshal(responseBody, &azErr)
32
return fmt.Errorf("Failed parsing contents to AzureError format: %v", err)