Skip to content

Commit

Permalink
slightly better 401 detection
Browse files Browse the repository at this point in the history
  • Loading branch information
asymmetricia committed Jul 24, 2024
1 parent dcc8ba6 commit cf153f4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions types/unifi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit cf153f4

Please sign in to comment.