resources: Add more details to .Err

This commit adds a .Data object (a map with `Body`, `StatusCode` etc.) to the .Err returned from `resources.GetRemote`, which means you can now do:

```
{{ with .Err }}
{{ range $k, $v := .Data }}
{{ end }}
{{ end }}
```

Fixes #9708
This commit is contained in:
Bjørn Erik Pedersen
2022-03-24 08:12:51 +01:00
parent a6fa290f67
commit 9202117ba0
10 changed files with 129 additions and 46 deletions

View File

@@ -151,8 +151,13 @@ func (ns *Namespace) GetRemote(args ...any) resource.Resource {
r, err := get(args...)
if err != nil {
// This allows the client to reason about the .Err in the template.
return resources.NewErrorResource(errors.Wrap(err, "error calling resources.GetRemote"))
switch v := err.(type) {
case *create.HTTPError:
return resources.NewErrorResource(resource.NewResourceError(v, v.Data))
default:
return resources.NewErrorResource(resource.NewResourceError(errors.Wrap(err, "error calling resources.GetRemote"), make(map[string]any)))
}
}
return r