Add error handling for Cloudflare API response status codes
This commit is contained in:
@@ -349,6 +349,11 @@ func getCloudflareZoneID(apiToken, zoneName string) (string, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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 {
|
var result struct {
|
||||||
Result []struct {
|
Result []struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
@@ -374,6 +379,11 @@ func getCloudflareRecordID(apiToken, zoneID, recordName, recordType string) (id,
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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 {
|
var result struct {
|
||||||
Result []cloudflareRecord `json:"result"`
|
Result []cloudflareRecord `json:"result"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user