forked from TrueCloudLab/lego
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).
This commit is contained in:
parent
91b13b10b9
commit
2e0e9cd68f
1 changed files with 8 additions and 4 deletions
|
@ -87,11 +87,8 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{})
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
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)
|
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
|
var dynRes dynResponse
|
||||||
|
@ -100,6 +97,13 @@ func (d *DNSProvider) sendRequest(method, resource string, payload interface{})
|
||||||
return nil, err
|
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" {
|
if dynRes.Status == "failure" {
|
||||||
// TODO add better error handling
|
// TODO add better error handling
|
||||||
return nil, fmt.Errorf("Dyn API request failed: %s", dynRes.Messages)
|
return nil, fmt.Errorf("Dyn API request failed: %s", dynRes.Messages)
|
||||||
|
|
Loading…
Reference in a new issue