convert ifelseif to switch (#2529)

This commit is contained in:
Laurence Jones 2023-10-09 11:23:19 +01:00 committed by GitHub
parent 9ae8bd79c5
commit 0dd22e8b93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -112,15 +112,16 @@ func CrowdsecCTI(params ...any) (any, error) {
ctiResp, err := ctiClient.GetIPInfo(ip)
ctiClient.Logger.Debugf("request for %s took %v", ip, time.Since(before))
if err != nil {
if err == cticlient.ErrUnauthorized {
switch err {
case cticlient.ErrUnauthorized:
CTIApiEnabled = false
ctiClient.Logger.Errorf("Invalid API key provided, disabling CTI API")
return &cticlient.SmokeItem{}, cticlient.ErrUnauthorized
} else if err == cticlient.ErrLimit {
case cticlient.ErrLimit:
CTIBackOffUntil = time.Now().Add(CTIBackOffDuration)
ctiClient.Logger.Errorf("CTI API is throttled, will try again in %s", CTIBackOffDuration)
return &cticlient.SmokeItem{}, cticlient.ErrLimit
} else {
default:
ctiClient.Logger.Warnf("CTI API error : %s", err)
return &cticlient.SmokeItem{}, fmt.Errorf("unexpected error : %v", err)
}