Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
Expand All @@ -25,6 +26,8 @@ type ErrorMessage struct {
Message string `json:"message"`
}

var ErrNotFound = errors.New("not found")

// Client for the Hetzner DNS API.
type Client struct {
requestLock sync.Mutex
Expand Down
4 changes: 2 additions & 2 deletions internal/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestClientGetZoneReturnNilIfNotFound(t *testing.T) {

zone, err := client.GetZone(context.Background(), "12345678")

require.NoError(t, err)
require.Error(t, err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should check, if ErrNotFound is returned. I now there is an extra require func for it

assert.Nil(t, zone)
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func TestClientGetRecordReturnNilIfNotFound(t *testing.T) {

record, err := client.GetRecord(context.Background(), "irrelevant")

require.NoError(t, err)
require.Error(t, err)
assert.Nil(t, record)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/api/primary_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *Client) GetPrimaryServer(ctx context.Context, id string) (*PrimaryServe

switch resp.StatusCode {
case http.StatusNotFound:
return nil, fmt.Errorf("primary server %s not found", id)
return nil, fmt.Errorf("primary server %s: %w", id, ErrNotFound)
case http.StatusOK:
var response *PrimaryServerResponse

Expand Down
2 changes: 1 addition & 1 deletion internal/api/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *Client) GetRecord(ctx context.Context, recordID string) (*Record, error

switch resp.StatusCode {
case http.StatusNotFound:
return nil, nil
return nil, fmt.Errorf("record %s: %w", recordID, ErrNotFound)
case http.StatusOK:
var response *RecordResponse

Expand Down
2 changes: 1 addition & 1 deletion internal/api/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Client) GetZone(ctx context.Context, id string) (*Zone, error) {

switch resp.StatusCode {
case http.StatusNotFound:
return nil, nil
return nil, fmt.Errorf("zone %s: %w", id, ErrNotFound)
case http.StatusOK:
var response GetZoneResponse

Expand Down
3 changes: 2 additions & 1 deletion internal/provider/primary_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -228,7 +229,7 @@ func (r *primaryServerResource) Read(ctx context.Context, req resource.ReadReque

return nil
})
if err != nil && fmt.Sprint(err) != fmt.Sprintf("primary server %s not found", state.ID.ValueString()) {
if err != nil && !errors.Is(err, api.ErrNotFound) {
resp.Diagnostics.AddError("API Error", fmt.Sprintf("read primary server: %s", err))

return
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/record_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -258,7 +259,7 @@ func (r *recordResource) Read(ctx context.Context, req resource.ReadRequest, res

return nil
})
if err != nil {
if err != nil && !errors.Is(err, api.ErrNotFound) {
resp.Diagnostics.AddError("API Error", fmt.Sprintf("read record: %s", err))

return
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/zone_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"errors"
"fmt"
"regexp"
"time"
Expand Down Expand Up @@ -253,7 +254,7 @@ func (r *zoneResource) Read(ctx context.Context, req resource.ReadRequest, resp

return nil
})
if err != nil {
if err != nil && !errors.Is(err, api.ErrNotFound) {
resp.Diagnostics.AddError("API Error", fmt.Sprintf("read zone: %s", err))

return
Expand Down