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.
This commit is contained in:
Brian Goff
2018-11-07 16:02:48 -08:00
committed by Robbie Zhang
parent 1d76b1341e
commit cd42fdd7b8
15 changed files with 210 additions and 20 deletions

View File

@@ -0,0 +1,48 @@
package sfmesh
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
}

View File

@@ -462,7 +462,7 @@ func (p *SFMeshProvider) DeletePod(ctx context.Context, pod *v1.Pod) (err error)
_, err = p.appClient.Delete(ctx, p.resourceGroup, pod.Name)
if err != nil {
return err
return wrapError(err)
}
return nil