Error handling

This commit is contained in:
Brandon Rozek 2025-06-15 22:23:49 -04:00
parent 0df997d594
commit cc623bd90a
No known key found for this signature in database
GPG key ID: DFB0E78F805F4567

View file

@ -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}`);
}