Skip to content

Commit

Permalink
feat: add IsForbiddenErr error checking for 403s
Browse files Browse the repository at this point in the history
  • Loading branch information
GGabriele committed Jan 12, 2023
1 parent d718290 commit 697b56b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kong/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ func IsNotFoundErr(e error) bool {
}
return false
}

// IsForbiddenErr returns true if the error or its cause is
// a 403 response from Kong.
func IsForbiddenErr(e error) bool {
var apiErr *APIError
if errors.As(e, &apiErr) {
return apiErr.httpCode == http.StatusForbidden
}
return false
}
13 changes: 13 additions & 0 deletions kong/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,16 @@ func TestAPIError_Code(T *testing.T) {
require.True(ok)
assert.True(kongErr.Code() == 404)
}

func TestIsForbiddenErrE2E(T *testing.T) {
assert := assert.New(T)

client, err := NewTestClient(nil, nil)
assert.NoError(err)
assert.NotNil(client)

cgs, err := client.ConsumerGroups.ListAll(defaultCtx)
assert.Nil(cgs)
assert.NotNil(err)
assert.True(IsForbiddenErr(err))
}

0 comments on commit 697b56b

Please sign in to comment.