From cf153f4a922ca68999a682f25797f179a0951732 Mon Sep 17 00:00:00 2001 From: Tricia Bogen Date: Tue, 23 Jul 2024 22:48:25 -0700 Subject: [PATCH] slightly better 401 detection --- types/unifi.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/unifi.go b/types/unifi.go index 2ef59d6..7ec74ad 100644 --- a/types/unifi.go +++ b/types/unifi.go @@ -1,6 +1,7 @@ package types import ( + "errors" "fmt" "strings" "time" @@ -120,7 +121,7 @@ func NewUnifi(username, password, host string, port int, verifyTls bool, func (u *Unifi) clients(log zerolog.Logger) ([]Client, error) { sites, err := u.unifiClient.GetSites() - if err != nil && strings.Contains(err.Error(), "code from server 401") { + if errors.Is(err, unifi.ErrInvalidStatusCode) && strings.Contains(err.Error(), "401") { err = u.Login(log) if err == nil { sites, err = u.unifiClient.GetSites() @@ -131,7 +132,7 @@ func (u *Unifi) clients(log zerolog.Logger) ([]Client, error) { } unifiClients, err := u.unifiClient.GetClients(sites) - if err != nil && strings.Contains(err.Error(), "code from server 401") { + if errors.Is(err, unifi.ErrInvalidStatusCode) && strings.Contains(err.Error(), "401") { err = u.Login(log) if err == nil { unifiClients, err = u.unifiClient.GetClients(sites)