fix(noip): handle response body messages before checking status code

This commit is contained in:
Quentin McGaw
2024-11-12 12:34:11 +00:00
parent d221522e02
commit 80670048ed

View File

@@ -146,10 +146,6 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
} }
s := string(b) s := string(b)
if response.StatusCode != http.StatusOK {
return netip.Addr{}, fmt.Errorf("%w: %d: %s", errors.ErrHTTPStatusNotValid, response.StatusCode, s)
}
switch s { switch s {
case "": case "":
return netip.Addr{}, fmt.Errorf("%w", errors.ErrReceivedNoResult) return netip.Addr{}, fmt.Errorf("%w", errors.ErrReceivedNoResult)
@@ -167,7 +163,9 @@ func (p *Provider) Update(ctx context.Context, client *http.Client, ip netip.Add
return netip.Addr{}, fmt.Errorf("%w", errors.ErrHostnameNotExists) return netip.Addr{}, fmt.Errorf("%w", errors.ErrHostnameNotExists)
} }
if !strings.Contains(s, "nochg") && !strings.Contains(s, "good") { if response.StatusCode != http.StatusOK {
return netip.Addr{}, fmt.Errorf("%w: %d: %s", errors.ErrHTTPStatusNotValid, response.StatusCode, s)
} else if !strings.Contains(s, "nochg") && !strings.Contains(s, "good") {
return netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrUnknownResponse, s) return netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrUnknownResponse, s)
} }