Changed error handling in clients

Changed error handling in clients
This commit is contained in:
Ruslan Gabitov 2014-08-26 14:35:32 -07:00
Родитель 5f9268b9cc
Коммит 4254b3dfae
4 изменённых файлов: 37 добавлений и 31 удалений

Просмотреть файл

@ -11,19 +11,19 @@ func GetImageList() (ImageList, error){
imageList := ImageList{}
requestURL := "services/images"
response, azureErr := azure.SendAzureGetRequest(requestURL)
if azureErr != nil {
azure.PrintErrorAndExit(azureErr)
response, err := azure.SendAzureGetRequest(requestURL)
if err != nil {
return imageList, err
}
err := xml.Unmarshal(response, &imageList)
err = xml.Unmarshal(response, &imageList)
return imageList, err
}
func ResolveImageName(imageName string) (error) {
imageList, err := GetImageList()
if err != nil {
azure.PrintErrorAndExit(err)
return err
}
for _, image := range imageList.OSImages {

Просмотреть файл

@ -13,7 +13,7 @@ import (
func ResolveLocation(specifiedLocation string) (error) {
locations, err := GetLocationList()
if err != nil {
azure.PrintErrorAndExit(err)
return err
}
for _, location := range locations.Locations {
@ -36,12 +36,12 @@ func GetLocationList() (LocationList, error) {
locationList := LocationList{}
requestURL := "locations"
response, azureErr := azure.SendAzureGetRequest(requestURL)
if azureErr != nil {
azure.PrintErrorAndExit(azureErr)
response, err := azure.SendAzureGetRequest(requestURL)
if err != nil {
return locationList, err
}
err := xml.Unmarshal(response, &locationList)
err = xml.Unmarshal(response, &locationList)
if err != nil {
return locationList, err
}

Просмотреть файл

@ -13,12 +13,12 @@ func GetStorageServiceList() (*StorageServiceList, error){
storageServiceList := new(StorageServiceList)
requestURL := "services/storageservices"
response, azureErr := azure.SendAzureGetRequest(requestURL)
if azureErr != nil {
azure.PrintErrorAndExit(azureErr)
response, err := azure.SendAzureGetRequest(requestURL)
if err != nil {
return nil, err
}
err := xml.Unmarshal(response, storageServiceList)
err = xml.Unmarshal(response, storageServiceList)
if err != nil {
return storageServiceList, err
}
@ -26,20 +26,20 @@ func GetStorageServiceList() (*StorageServiceList, error){
return storageServiceList, nil
}
func GetStorageServiceByName(serviceName string) (*StorageService){
func GetStorageServiceByName(serviceName string) (*StorageService, error){
storageService := new(StorageService)
requestURL := fmt.Sprintf("services/storageservices/%s", serviceName)
response, azureErr := azure.SendAzureGetRequest(requestURL)
if azureErr != nil {
azure.PrintErrorAndExit(azureErr)
}
err := xml.Unmarshal(response, storageService)
response, err := azure.SendAzureGetRequest(requestURL)
if err != nil {
azure.PrintErrorAndExit(err)
return nil, err
}
return storageService
err = xml.Unmarshal(response, storageService)
if err != nil {
return nil, err
}
return storageService, nil
}
func GetStorageServiceByLocation(location string) (*StorageService, error) {
@ -60,23 +60,26 @@ func GetStorageServiceByLocation(location string) (*StorageService, error) {
return nil, nil
}
func CreateStorageService(name, location string) (*StorageService){
func CreateStorageService(name, location string) (*StorageService, error){
storageDeploymentConfig := createStorageServiceDeploymentConf(name, location)
deploymentBytes, err := xml.Marshal(storageDeploymentConfig)
if err != nil {
azure.PrintErrorAndExit(err)
return nil, err
}
requestURL := "services/storageservices"
requestId, azureErr := azure.SendAzurePostRequest(requestURL, deploymentBytes)
if azureErr != nil {
azure.PrintErrorAndExit(azureErr)
requestId, err := azure.SendAzurePostRequest(requestURL, deploymentBytes)
if err != nil {
return nil, err
}
azure.WaitAsyncOperation(requestId)
storageService := GetStorageServiceByName(storageDeploymentConfig.ServiceName)
storageService, err := GetStorageServiceByName(storageDeploymentConfig.ServiceName)
if err != nil {
return nil, err
}
return storageService
return storageService, nil
}
func GetBlobEndpoint(storageService *StorageService) (string, error) {

Просмотреть файл

@ -440,7 +440,10 @@ func getVHDMediaLink(dnsName, location string) (string, error){
}
serviceName := "portalvhds" + uuid
storageService = storageServiceClient.CreateStorageService(serviceName, location)
storageService, err = storageServiceClient.CreateStorageService(serviceName, location)
if err != nil {
return "", err
}
}
blobEndpoint, err := storageServiceClient.GetBlobEndpoint(storageService)