Skip to content

Commit

Permalink
fix: getRecord handles all possible status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Oct 20, 2024
1 parent a7e9b0a commit 1fd9ce5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/provider/providers/vultr/getrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1fd9ce5

Please sign in to comment.