From 2e0e9cd68f0dd462a61a353129ac720b16b7883b Mon Sep 17 00:00:00 2001 From: Remi Broemeling Date: Mon, 19 Mar 2018 10:41:57 -0600 Subject: [PATCH] Slightly improve Dyn provider error reporting. (#473) If Dyn responds with a 3xx or 4xx status code, information describing exactly what went wrong is generally included in the body of the response (as part of the typical Dyn JSON response). On the other hand, if Dyn responds with a 5xx status code, we very likely have extremely limited information. This commit modifies the reporting to display the explanatory messages included in the body of the Dyn response for 3xx and 4xx status codes. The intent is to make it much easier to determine what might be going wrong (when something is going wrong). --- providers/dns/dyn/dyn.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/providers/dns/dyn/dyn.go b/providers/dns/dyn/dyn.go index 384bc850..277dffb9 100644 --- a/providers/dns/dyn/dyn.go +++ b/providers/dns/dyn/dyn.go @@ -87,11 +87,8 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) } defer resp.Body.Close() - if resp.StatusCode >= 400 { + if resp.StatusCode >= 500 { return nil, fmt.Errorf("Dyn API request failed with HTTP status code %d", resp.StatusCode) - } else if resp.StatusCode == 307 { - // TODO add support for HTTP 307 response and long running jobs - return nil, fmt.Errorf("Dyn API request returned HTTP 307. This is currently unsupported") } var dynRes dynResponse @@ -100,6 +97,13 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{}) return nil, err } + if resp.StatusCode >= 400 { + return nil, fmt.Errorf("Dyn API request failed with HTTP status code %d: %s", resp.StatusCode, dynRes.Messages) + } else if resp.StatusCode == 307 { + // TODO add support for HTTP 307 response and long running jobs + return nil, fmt.Errorf("Dyn API request returned HTTP 307. This is currently unsupported") + } + if dynRes.Status == "failure" { // TODO add better error handling return nil, fmt.Errorf("Dyn API request failed: %s", dynRes.Messages)