Skip to content

Commit

Permalink
PR feedback: don't introduce an error for viceroy behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-dub committed Dec 19, 2023
1 parent cab1c87 commit 4e7de5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions geo/geodata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import (
)

var (
// ErrNotFound indicates there was no geo data returned.
ErrNotFound = errors.New("geo: no data found")

// ErrInvalidIP indicates the input IP was invalid.
ErrInvalidIP = errors.New("geo: invalid IP")

Expand Down Expand Up @@ -51,7 +48,12 @@ func Lookup(ip net.IP) (*Geo, error) {
status, ok := fastly.IsFastlyError(err)
switch {
case ok && status == fastly.FastlyStatusNone:
return nil, ErrNotFound
// Viceroy <= 0.9.3 returns fastly.FastlyStatusNone when no geolocation
// data is available. The Compute production environment instead returns
// empty data, which is handled by falling through to code below this switch.

// TODO: potential breaking change if bumping major version
// return nil, ErrNotFound
case ok && status == fastly.FastlyStatusInval:
return nil, ErrInvalidIP
case ok:
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/geolocation/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestGeolocation(t *testing.T) {

t.Run("not found", func(t *testing.T) {
g, err := geo.Lookup(net.ParseIP("127.0.0.9"))
assert(t, "Geo{}", g, nil)
assert(t, "err", err, geo.ErrNotFound)
assert(t, "Geo{}", *g, geo.Geo{})
assert(t, "err", err, nil)
})

t.Run("invalid", func(t *testing.T) {
Expand Down

0 comments on commit 4e7de5d

Please sign in to comment.