Skip to content

Commit 1fd9ce5

Browse files
committed
fix: getRecord handles all possible status codes
1 parent a7e9b0a commit 1fd9ce5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

internal/provider/providers/vultr/getrecord.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,21 @@ func (p *Provider) getRecord(ctx context.Context, client *http.Client,
7070
switch {
7171
case err != nil:
7272
return "", netip.Addr{}, fmt.Errorf("json decoding response body: %w", err)
73-
case parsedJSON.Error != "":
74-
return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrUnsuccessful, parsedJSON.Error)
73+
case response.StatusCode == http.StatusBadRequest:
74+
return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrBadRequest, parsedJSON.Error)
75+
case response.StatusCode == http.StatusUnauthorized:
76+
return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrAuth, parsedJSON.Error)
77+
case response.StatusCode == http.StatusNotFound:
78+
return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrDomainNotFound, parsedJSON.Error)
7579
case response.StatusCode != http.StatusOK:
7680
return "", netip.Addr{}, fmt.Errorf("%w: %d: %s",
7781
errors.ErrHTTPStatusNotValid, response.StatusCode, parseJSONErrorOrFullBody(bodyBytes))
82+
case parsedJSON.Error != "":
83+
return "", netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrUnsuccessful, parsedJSON.Error)
7884
}
7985

86+
// Status is OK (200) and error field is empty
87+
8088
for _, record := range parsedJSON.Records {
8189
if record.Name != p.owner || record.Type != recordType {
8290
continue

0 commit comments

Comments
 (0)