1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Switch from fmt.Error* to errors.Error* (#317)

This commit is contained in:
Tom Limoncelli
2018-02-05 16:17:20 -05:00
committed by GitHub
parent 65f8fb63f0
commit 4b1dc82c9b
31 changed files with 162 additions and 140 deletions

View File

@@ -12,6 +12,7 @@ import (
"strconv"
"github.com/StackExchange/dnscontrol/models"
"github.com/pkg/errors"
)
const (
@@ -32,10 +33,10 @@ func (c *CloudflareApi) fetchDomainList() error {
zr := &zoneResponse{}
url := fmt.Sprintf("%s?page=%d&per_page=50", zonesURL, page)
if err := c.get(url, zr); err != nil {
return fmt.Errorf("Error fetching domain list from cloudflare: %s", err)
return errors.Errorf("Error fetching domain list from cloudflare: %s", err)
}
if !zr.Success {
return fmt.Errorf("Error fetching domain list from cloudflare: %s", stringifyErrors(zr.Errors))
return errors.Errorf("Error fetching domain list from cloudflare: %s", stringifyErrors(zr.Errors))
}
for _, zone := range zr.Result {
c.domainIndex[zone.Name] = zone.ID
@@ -61,10 +62,10 @@ func (c *CloudflareApi) getRecordsForDomain(id string, domain string) ([]*models
reqURL := fmt.Sprintf("%s?page=%d&per_page=100", url, page)
var data recordsResponse
if err := c.get(reqURL, &data); err != nil {
return nil, fmt.Errorf("Error fetching record list from cloudflare: %s", err)
return nil, errors.Errorf("Error fetching record list from cloudflare: %s", err)
}
if !data.Success {
return nil, fmt.Errorf("Error fetching record list cloudflare: %s", stringifyErrors(data.Errors))
return nil, errors.Errorf("Error fetching record list cloudflare: %s", stringifyErrors(data.Errors))
}
for _, rec := range data.Result {
// fmt.Printf("REC: %+v\n", rec)
@@ -202,7 +203,7 @@ func (c *CloudflareApi) createRec(rec *models.RecordConfig, domainID string) []*
func (c *CloudflareApi) modifyRecord(domainID, recID string, proxied bool, rec *models.RecordConfig) error {
if domainID == "" || recID == "" {
return fmt.Errorf("cannot modify record if domain or record id are empty")
return errors.Errorf("cannot modify record if domain or record id are empty")
}
type record struct {
ID string `json:"id"`
@@ -247,10 +248,10 @@ func handleActionResponse(resp *http.Response, err error) (id string, e error) {
result := &basicResponse{}
decoder := json.NewDecoder(resp.Body)
if err = decoder.Decode(result); err != nil {
return "", fmt.Errorf("Unknown error. Status code: %d", resp.StatusCode)
return "", errors.Errorf("Unknown error. Status code: %d", resp.StatusCode)
}
if resp.StatusCode != 200 {
return "", fmt.Errorf(stringifyErrors(result.Errors))
return "", errors.Errorf(stringifyErrors(result.Errors))
}
return result.Result.ID, nil
}
@@ -273,7 +274,7 @@ func (c *CloudflareApi) get(endpoint string, target interface{}) error {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("bad status code from cloudflare: %d not 200", resp.StatusCode)
return errors.Errorf("bad status code from cloudflare: %d not 200", resp.StatusCode)
}
decoder := json.NewDecoder(resp.Body)
return decoder.Decode(target)
@@ -283,10 +284,10 @@ func (c *CloudflareApi) getPageRules(id string, domain string) ([]*models.Record
url := fmt.Sprintf(pageRulesURL, id)
data := pageRuleResponse{}
if err := c.get(url, &data); err != nil {
return nil, fmt.Errorf("Error fetching page rule list from cloudflare: %s", err)
return nil, errors.Errorf("Error fetching page rule list from cloudflare: %s", err)
}
if !data.Success {
return nil, fmt.Errorf("Error fetching page rule list cloudflare: %s", stringifyErrors(data.Errors))
return nil, errors.Errorf("Error fetching page rule list cloudflare: %s", stringifyErrors(data.Errors))
}
recs := []*models.RecordConfig{}
for _, pr := range data.Result {