Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,19 @@ func decodeBody(resp *http.Response, out interface{}) error {
// checkResp wraps http.Client.Do() and verifies that the
// request was successful. A non-200 request returns an error
// formatted to included any validation problems or otherwise
func checkResp(resp *http.Response, err error) (*http.Response, error) {
func checkResp(resp *http.Response, err error) (*http.Response, error, string) {
// If the err is already there, there was an error higher
// up the chain, so just return that
if err != nil {
return resp, err
return resp, err, "N/A"
}

reqid := resp.Header.Get("x-dnsme-requestId")

if resp.StatusCode/100 == 2 {
return resp, nil
return resp, nil, reqid
} else if resp.StatusCode == 404 {
return nil, fmt.Errorf("Not found")
return nil, fmt.Errorf("Not found"), reqid
}
return nil, fmt.Errorf("API Error: %s", resp.Status)
return nil, fmt.Errorf("API Error: %s", resp.Status), reqid
}
19 changes: 11 additions & 8 deletions record.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func (c *Client) CreateRecord(domainID string, cr map[string]interface{}) (strin
return "", fmt.Errorf("Error from NewRequest: %s", err)
}

resp, err := checkResp(c.HTTP.Do(req))
resp, err, reqid := checkResp(c.HTTP.Do(req))
if err != nil {
return "", fmt.Errorf("Error creating record: %s", err)
return "", fmt.Errorf("Error creating record: %s\n\tRequestID %s", err, reqid)
}

record := new(Record)
Expand All @@ -109,9 +109,9 @@ func (c *Client) ReadRecord(domainID string, recordID string) (*Record, error) {
return nil, err
}

resp, err := checkResp(c.HTTP.Do(req))
resp, err, reqid := checkResp(c.HTTP.Do(req))
if err != nil {
return nil, fmt.Errorf("Error retrieving record: %s", err)
return nil, fmt.Errorf("Error retrieving record: %s\n\tRequestID %s", err, reqid)
}

dataResp := DataResponse{}
Expand Down Expand Up @@ -139,6 +139,8 @@ func (c *Client) ReadRecord(domainID string, recordID string) (*Record, error) {
// returns an error if it fails.
func (c *Client) UpdateRecord(domainID string, recordID string, cr map[string]interface{}) (string, error) {

var reqid string

current, err := c.ReadRecord(domainID, recordID)
if err != nil {
return "", err
Expand All @@ -161,9 +163,9 @@ func (c *Client) UpdateRecord(domainID string, recordID string, cr map[string]in
return "", err
}

_, err = checkResp(c.HTTP.Do(req))
_, err, reqid = checkResp(c.HTTP.Do(req))
if err != nil {
return "", fmt.Errorf("Error updating record: %s", err)
return "", fmt.Errorf("Error updating record: %s\n\tRequestID %s", err, reqid)
}

// The request was successful
Expand All @@ -174,16 +176,17 @@ func (c *Client) UpdateRecord(domainID string, recordID string, cr map[string]in
// returns an error if it fails. If no error is returned,
// the Record was succesfully destroyed.
func (c *Client) DeleteRecord(domainID string, recordID string) error {
var reqid string
body := bytes.NewBuffer(nil)
path := destroy.endpoint(domainID, recordID)
req, err := c.NewRequest("DELETE", path, body, "")
if err != nil {
return err
}

_, err = checkResp(c.HTTP.Do(req))
_, err, reqid = checkResp(c.HTTP.Do(req))
if err != nil {
return fmt.Errorf("Unable to find record %s", recordID)
return fmt.Errorf("Unable to find record %s\n\tRequestID %s", recordID, reqid)
}

// The request was successful
Expand Down