Skip to content

Commit

Permalink
dns: return a dedicated error when record ID is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Jan 10, 2023
1 parent 095641f commit c58af05
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudflare
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -192,6 +193,9 @@ func (api *API) ListDNSRecords(ctx context.Context, rc *ResourceContainer, param
return records, &listResponse.ResultInfo, nil
}

// ErrMissingDNSRecordID is for when DNS record ID is needed but not given.
var ErrMissingDNSRecordID = errors.New("required DNS record ID missing")

// GetDNSRecord returns a single DNS record for the given zone & record
// identifiers.
//
Expand All @@ -200,6 +204,10 @@ func (api *API) GetDNSRecord(ctx context.Context, rc *ResourceContainer, recordI
if rc.Identifier == "" {
return DNSRecord{}, ErrMissingZoneID
}
if recordID == "" {
return DNSRecord{}, ErrMissingDNSRecordID
}

uri := fmt.Sprintf("/zones/%s/dns_records/%s", rc.Identifier, recordID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
Expand All @@ -221,6 +229,9 @@ func (api *API) UpdateDNSRecord(ctx context.Context, rc *ResourceContainer, para
if rc.Identifier == "" {
return ErrMissingZoneID
}
if params.ID == "" {
return ErrMissingDNSRecordID
}

params.Name = toUTS46ASCII(params.Name)

Expand Down

0 comments on commit c58af05

Please sign in to comment.