From cc623bd90af3b0ad4c0cd0d47ac5bcacf664aff1 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Sun, 15 Jun 2025 22:23:49 -0400 Subject: [PATCH] Error handling --- layouts/partials/highfive.html | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/layouts/partials/highfive.html b/layouts/partials/highfive.html index a40c668..0ff1f1f 100644 --- a/layouts/partials/highfive.html +++ b/layouts/partials/highfive.html @@ -38,9 +38,14 @@ {{ $resource := resources.GetRemote $apiUrl }} {{ $initialCount := 0 }} {{ if $resource }} - {{ $highfiveData := $resource | transform.Unmarshal }} - {{ if $highfiveData.count }} - {{ $initialCount = $highfiveData.count }} + {{ with $resource.Err }} + {{ warnf "Failed to fetch highfive data from %s: %s" $apiUrl . }} + {{ $initialCount = 0 }} + {{ else }} + {{ $highfiveData := $resource | transform.Unmarshal }} + {{ if $highfiveData.count }} + {{ $initialCount = $highfiveData.count }} + {{ end }} {{ end }} {{ end }} @@ -117,6 +122,10 @@ return { ...data, alreadyHighFived: true }; } + if (response.status === 400) { + return {count: 0} + } + if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); }