mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
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:
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user