From 78716b10d8d03bec7812cf3efad804b314607577 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Sun, 19 Jan 2025 10:05:12 -0800 Subject: [PATCH] Use try function --- layouts/partials/paige/resource.html | 6 ++++-- layouts/shortcodes/paige/request.html | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/layouts/partials/paige/resource.html b/layouts/partials/paige/resource.html index 0ad1101a..32621d69 100644 --- a/layouts/partials/paige/resource.html +++ b/layouts/partials/paige/resource.html @@ -6,11 +6,13 @@ {{ $result := "" }} {{ if (urls.Parse $url).Scheme }} - {{ with resources.GetRemote $url }} + {{ with try (resources.GetRemote $url) }} {{ with .Err }} {{ errorf "layouts/partials/paige/resource.html: cannot get remote resource %q: %v" $url . }} - {{ else }} + {{ else with .Value }} {{ $result = . }} + {{ else }} + {{ errorf "layouts/partials/paige/resource.html: remote resource %q not found" $url }} {{ end }} {{ end }} {{ end }} diff --git a/layouts/shortcodes/paige/request.html b/layouts/shortcodes/paige/request.html index 7758d651..250cb97a 100644 --- a/layouts/shortcodes/paige/request.html +++ b/layouts/shortcodes/paige/request.html @@ -5,12 +5,12 @@ {{- errorf "layouts/shortcodes/paige/request.html: no url" -}} {{- end -}} -{{- with resources.GetRemote $url (dict "method" $method) -}} +{{- with try (resources.GetRemote $url (dict "method" $method)) -}} {{- with .Err -}} {{- errorf "layouts/shortcodes/paige/request.html: cannot request remote resource %q: %v" $url . -}} + {{- else with .Value -}} + {{- strings.TrimRight "\f\n\r\t\v " . -}} {{- else -}} - {{- strings.TrimRight "\f\n\r\t\v " .Content -}} + {{- errorf "layouts/shortcodes/paige/request.html: remote resource %q not found" $url -}} {{- end -}} -{{- else -}} - {{- errorf "layouts/shortcodes/paige/request.html: cannot request remote resource %q" $url -}} {{- end -}}