From 7a03aa694261ac96411f04adc83b3f25b38c314d Mon Sep 17 00:00:00 2001 From: imlonghao Date: Sat, 15 Jun 2024 11:04:07 +0800 Subject: [PATCH] PORKBUN: catch error on parsing api --- providers/porkbun/api.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/providers/porkbun/api.go b/providers/porkbun/api.go index 066cf50855..003a371771 100644 --- a/providers/porkbun/api.go +++ b/providers/porkbun/api.go @@ -134,7 +134,10 @@ func (c *porkbunProvider) getRecords(domain string) ([]domainRecord, error) { } var dr recordResponse - json.Unmarshal(bodyString, &dr) + err = json.Unmarshal(bodyString, &dr) + if err != nil { + return nil, fmt.Errorf("failed parsing record list from porkbun: %w", err) + } var records []domainRecord for _, rec := range dr.Records { @@ -154,7 +157,10 @@ func (c *porkbunProvider) getNameservers(domain string) ([]string, error) { } var ns nsResponse - json.Unmarshal(bodyString, &ns) + err = json.Unmarshal(bodyString, &ns) + if err != nil { + return nil, fmt.Errorf("failed parsing nameserver list from porkbun: %w", err) + } sort.Strings(ns.Nameservers) @@ -185,7 +191,10 @@ func (c *porkbunProvider) listAllDomains() ([]string, error) { } var dlr domainListResponse - json.Unmarshal(bodyString, &dlr) + err = json.Unmarshal(bodyString, &dlr) + if err != nil { + return nil, fmt.Errorf("failed parsing domain list from porkbun: %w", err) + } var domains []string for _, domain := range dlr.Domains {