From d0b645b9b57caf4a8e88c2099fa20f3f9fcb6fc8 Mon Sep 17 00:00:00 2001 From: Paul Payne Date: Sun, 12 Jul 2026 21:55:43 +0000 Subject: [PATCH] Add error handling for Cloudflare API response status codes --- internal/ddns/cloudflare.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/ddns/cloudflare.go b/internal/ddns/cloudflare.go index 2945a27..8b287c1 100644 --- a/internal/ddns/cloudflare.go +++ b/internal/ddns/cloudflare.go @@ -349,6 +349,11 @@ func getCloudflareZoneID(apiToken, zoneName string) (string, error) { } defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + b, _ := io.ReadAll(resp.Body) + return "", fmt.Errorf("cloudflare API returned %d: %s", resp.StatusCode, string(b)) + } + var result struct { Result []struct { ID string `json:"id"` @@ -374,6 +379,11 @@ func getCloudflareRecordID(apiToken, zoneID, recordName, recordType string) (id, } defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + b, _ := io.ReadAll(resp.Body) + return "", "", fmt.Errorf("cloudflare API returned %d: %s", resp.StatusCode, string(b)) + } + var result struct { Result []cloudflareRecord `json:"result"` }