mirror of
https://github.com/helm/helm.git
synced 2026-05-25 18:54:23 -04:00
chore: handle specific errors
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
This commit is contained in:
parent
496031f299
commit
4d55d14033
2 changed files with 50 additions and 1 deletions
|
|
@ -97,7 +97,8 @@ func (a *Authorizer) Do(originalReq *http.Request) (*http.Response, error) {
|
|||
a.setAttemptBearerAuthentication(false)
|
||||
return resp, nil
|
||||
}
|
||||
if !strings.Contains(err.Error(), "response status code 40") {
|
||||
if !strings.Contains(err.Error(), "response status code 401") &&
|
||||
!strings.Contains(err.Error(), "response status code 403") {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ package registry
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
|
|
@ -295,3 +297,49 @@ func TestAuthorizer_ConcurrentAccess(t *testing.T) {
|
|||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestAuthorizer_Do_StatusCodeErrorChecking(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
errorMsg string
|
||||
shouldRetry bool
|
||||
description string
|
||||
}{
|
||||
{
|
||||
name: "retry on 401 error",
|
||||
errorMsg: "response status code 401",
|
||||
shouldRetry: true,
|
||||
description: "401 errors should trigger retry logic",
|
||||
},
|
||||
{
|
||||
name: "retry on 403 error",
|
||||
errorMsg: "response status code 403",
|
||||
shouldRetry: true,
|
||||
description: "403 errors should trigger retry logic",
|
||||
},
|
||||
{
|
||||
name: "no retry on 404 error",
|
||||
errorMsg: "response status code 404",
|
||||
shouldRetry: false,
|
||||
description: "404 errors should not trigger retry logic",
|
||||
},
|
||||
{
|
||||
name: "no retry on 500 error",
|
||||
errorMsg: "response status code 500",
|
||||
shouldRetry: false,
|
||||
description: "500 errors should not trigger retry logic",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := errors.New(tt.errorMsg)
|
||||
|
||||
should401Retry := strings.Contains(err.Error(), "response status code 401")
|
||||
should403Retry := strings.Contains(err.Error(), "response status code 403")
|
||||
actualShouldRetry := should401Retry || should403Retry
|
||||
|
||||
assert.Equal(t, tt.shouldRetry, actualShouldRetry, tt.description)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue