Skip to content

Commit

Permalink
need to handled unexpected error types...like validation.error (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
frodopwns authored Aug 20, 2019
1 parent daf4247 commit 1e26f3a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions pkg/errhelp/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,29 @@ const (
)

func NewAzureError(err error) error {
det := err.(autorest.DetailedError)
code := det.StatusCode.(int)
var kind, reason string
if e, ok := det.Original.(*azure.RequestError); ok {
kind = e.ServiceError.Code
reason = e.ServiceError.Message
} else if e, ok := det.Original.(*azure.ServiceError); ok {
kind = e.Code
reason = e.Message
} else if _, ok := det.Original.(*errors.StatusError); ok {
kind = "StatusError"
reason = "StatusError"
ae := AzureError{
Original: err,
}
//det := err.(autorest.DetailedError)

return &AzureError{Type: kind, Reason: reason, Code: code, Original: err}
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
} else if e, ok := det.Original.(*azure.ServiceError); ok {
kind = e.Code
reason = e.Message
} else if _, ok := det.Original.(*errors.StatusError); ok {
kind = "StatusError"
reason = "StatusError"
}
ae.Reason = reason
ae.Type = kind
}
return &ae
}

type AzureError struct {
Expand All @@ -38,5 +46,5 @@ type AzureError struct {
}

func (e AzureError) Error() string {
return e.Type
return e.Original.Error()
}

0 comments on commit 1e26f3a

Please sign in to comment.