From 1fd9ce5b8c8b817060160d61cac6d77ac501853f Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sun, 20 Oct 2024 17:35:46 +0000 Subject: [PATCH] fix: getRecord handles all possible status codes --- internal/provider/providers/vultr/getrecord.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/provider/providers/vultr/getrecord.go b/internal/provider/providers/vultr/getrecord.go index b45f1f549..ad8dc42ae 100644 --- a/internal/provider/providers/vultr/getrecord.go +++ b/internal/provider/providers/vultr/getrecord.go @@ -70,13 +70,21 @@ func (p *Provider) getRecord(ctx context.Context, client *http.Client, switch { case err != nil: return "", netip.Addr{}, fmt.Errorf("json decoding response body: %w", err) - case parsedJSON.Error != "": - return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrUnsuccessful, parsedJSON.Error) + case response.StatusCode == http.StatusBadRequest: + return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrBadRequest, parsedJSON.Error) + case response.StatusCode == http.StatusUnauthorized: + return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrAuth, parsedJSON.Error) + case response.StatusCode == http.StatusNotFound: + return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrDomainNotFound, parsedJSON.Error) case response.StatusCode != http.StatusOK: return "", netip.Addr{}, fmt.Errorf("%w: %d: %s", errors.ErrHTTPStatusNotValid, response.StatusCode, parseJSONErrorOrFullBody(bodyBytes)) + case parsedJSON.Error != "": + return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrUnsuccessful, parsedJSON.Error) } + // Status is OK (200) and error field is empty + for _, record := range parsedJSON.Records { if record.Name != p.owner || record.Type != recordType { continue