diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-03-24 08:12:51 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-03-25 16:40:36 +0100 |
commit | 9202117ba08286975c723130db60a1c69ff249a0 (patch) | |
tree | 2b5bc26059e47045edaa4bb5ddeb89f4da6a68cd /tpl | |
parent | a6fa290f67a858e813480cd19bd5e8e1088771d2 (diff) | |
download | hugo-9202117ba08286975c723130db60a1c69ff249a0.tar.gz hugo-9202117ba08286975c723130db60a1c69ff249a0.zip |
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
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/resources/resources.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go index f4b5b0719..7e137c661 100644 --- a/tpl/resources/resources.go +++ b/tpl/resources/resources.go @@ -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 |