Add error handling for Cloudflare API response status codes

This commit is contained in:
2026-07-12 21:55:43 +00:00
parent 1d1d6c605c
commit d0b645b9b5

View File

@@ -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"`
}