convert ifelseif to switch (#2529)
This commit is contained in:
parent
9ae8bd79c5
commit
0dd22e8b93
|
@ -112,15 +112,16 @@ func CrowdsecCTI(params ...any) (any, error) {
|
||||||
ctiResp, err := ctiClient.GetIPInfo(ip)
|
ctiResp, err := ctiClient.GetIPInfo(ip)
|
||||||
ctiClient.Logger.Debugf("request for %s took %v", ip, time.Since(before))
|
ctiClient.Logger.Debugf("request for %s took %v", ip, time.Since(before))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == cticlient.ErrUnauthorized {
|
switch err {
|
||||||
|
case cticlient.ErrUnauthorized:
|
||||||
CTIApiEnabled = false
|
CTIApiEnabled = false
|
||||||
ctiClient.Logger.Errorf("Invalid API key provided, disabling CTI API")
|
ctiClient.Logger.Errorf("Invalid API key provided, disabling CTI API")
|
||||||
return &cticlient.SmokeItem{}, cticlient.ErrUnauthorized
|
return &cticlient.SmokeItem{}, cticlient.ErrUnauthorized
|
||||||
} else if err == cticlient.ErrLimit {
|
case cticlient.ErrLimit:
|
||||||
CTIBackOffUntil = time.Now().Add(CTIBackOffDuration)
|
CTIBackOffUntil = time.Now().Add(CTIBackOffDuration)
|
||||||
ctiClient.Logger.Errorf("CTI API is throttled, will try again in %s", CTIBackOffDuration)
|
ctiClient.Logger.Errorf("CTI API is throttled, will try again in %s", CTIBackOffDuration)
|
||||||
return &cticlient.SmokeItem{}, cticlient.ErrLimit
|
return &cticlient.SmokeItem{}, cticlient.ErrLimit
|
||||||
} else {
|
default:
|
||||||
ctiClient.Logger.Warnf("CTI API error : %s", err)
|
ctiClient.Logger.Warnf("CTI API error : %s", err)
|
||||||
return &cticlient.SmokeItem{}, fmt.Errorf("unexpected error : %v", err)
|
return &cticlient.SmokeItem{}, fmt.Errorf("unexpected error : %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue