github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/provider/azure/internal/errorutils/errors.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package errorutils 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/Azure/go-autorest/autorest" 10 "github.com/Azure/go-autorest/autorest/azure" 11 ) 12 13 // ServiceError returns the *azure.ServiceError underlying the 14 // supplied error, if any, and a bool indicating whether one 15 // was found. 16 func ServiceError(err error) (*azure.ServiceError, bool) { 17 err = errors.Cause(err) 18 if d, ok := err.(autorest.DetailedError); ok { 19 err = d.Original 20 } 21 if r, ok := err.(*azure.RequestError); ok { 22 return r.ServiceError, true 23 } 24 return nil, false 25 }