This ensures that we can catch certain types of errors from providers and handle accordingly in the core. There is still more to do here to improve that but this resolves an immediate need to know why a Delete failed. vic provider was not updated since I could not figure out where to get this information.
49 lines
829 B
Go
49 lines
829 B
Go
package azurebatch
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/Azure/go-autorest/autorest"
|
|
"github.com/Azure/go-autorest/autorest/azure"
|
|
"github.com/cpuguy83/strongerrors"
|
|
)
|
|
|
|
func wrapError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
switch {
|
|
case isStatus(err, http.StatusNotFound):
|
|
return strongerrors.NotFound(err)
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
type causal interface {
|
|
Cause() error
|
|
}
|
|
|
|
func isStatus(err error, status int) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
|
|
switch e := err.(type) {
|
|
case *azure.RequestError:
|
|
if e.StatusCode != 0 {
|
|
return e.StatusCode == status
|
|
}
|
|
return isStatus(e.Original, status)
|
|
case autorest.DetailedError:
|
|
if e.StatusCode != 0 {
|
|
return e.StatusCode == status
|
|
}
|
|
return isStatus(e.Original, status)
|
|
case causal:
|
|
return isStatus(e.Cause(), status)
|
|
}
|
|
|
|
return false
|
|
}
|