Improve authenticator error handling

From PR Review https://github.com/safing/portbase/pull/59
This commit is contained in:
Daniel 2020-07-10 13:21:10 +02:00
parent eb0cbf58a8
commit 2fa29789de
2 changed files with 3 additions and 2 deletions

View file

@ -38,7 +38,7 @@ type Authenticator func(ctx context.Context, s *http.Server, r *http.Request) (e
// SetAuthenticator sets an authenticator function for the API endpoint. If none is set, all requests will be permitted.
func SetAuthenticator(fn Authenticator) error {
if module.Online() {
return ErrAuthenticationAlreadySet
return ErrAuthenticationImmutable
}
authFnLock.Lock()

View file

@ -14,7 +14,8 @@ var (
// API Errors
var (
ErrAuthenticationAlreadySet = errors.New("the authentication function has already been set (or must be set earlier)")
ErrAuthenticationAlreadySet = errors.New("the authentication function has already been set")
ErrAuthenticationImmutable = errors.New("the authentication function can only be set before the api has started")
)
func init() {