...

Source file src/github.com/Azure/azure-sdk-for-go/services/classic/management/errors.go

Documentation: github.com/Azure/azure-sdk-for-go/services/classic/management

     1  // +build go1.7
     2  
     3  package management
     4  
     5  // Copyright (c) Microsoft Corporation. All rights reserved.
     6  // Licensed under the MIT License. See License.txt in the project root for license information.
     7  
     8  import (
     9  	"encoding/xml"
    10  	"fmt"
    11  )
    12  
    13  // AzureError represents an error returned by the management API. It has an error
    14  // code (for example, ResourceNotFound) and a descriptive message.
    15  type AzureError struct {
    16  	Code    string
    17  	Message string
    18  }
    19  
    20  //Error implements the error interface for the AzureError type.
    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  // IsResourceNotFoundError returns true if the provided error is an AzureError
    26  // reporting that a given resource has not been found.
    27  func IsResourceNotFoundError(err error) bool {
    28  	azureErr, ok := err.(AzureError)
    29  	return ok && azureErr.Code == "ResourceNotFound"
    30  }
    31  
    32  // getAzureError converts an error response body into an AzureError instance.
    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