Files
virtual-kubelet/providers/azurebatch/errors.go
Brian Goff cd42fdd7b8 Use strongerrors in provider implementations. (#403)
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.
2018-11-07 16:02:48 -08:00

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
}