need to handled unexpected error types...like validation.error
@@ -13,9 +13,15 @@ const (
)
func NewAzureError(err error) error {
- det := err.(autorest.DetailedError)
- code := det.StatusCode.(int)
+ ae := AzureError{
+ Original: err,
+ }
+ //det := err.(autorest.DetailedError)
+
+ if det, ok := err.(autorest.DetailedError); ok {
var kind, reason string
+ ae.Code = det.StatusCode.(int)
+
if e, ok := det.Original.(*azure.RequestError); ok {
kind = e.ServiceError.Code
reason = e.ServiceError.Message
@@ -26,8 +32,10 @@ func NewAzureError(err error) error {
kind = "StatusError"
reason = "StatusError"
}
-
- return &AzureError{Type: kind, Reason: reason, Code: code, Original: err}
+ ae.Reason = reason
+ ae.Type = kind
+ }
+ return &ae
}
type AzureError struct {
@@ -38,5 +46,5 @@ type AzureError struct {
}
func (e AzureError) Error() string {
- return e.Type
+ return e.Original.Error()
}
