Skip to content

Commit 43083ec

Browse files
author
Pascal Minder
committed
Improve error logging
1 parent 4e30de4 commit 43083ec

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

geoblock.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ func (a *GeoBlock) allowDenyCachedRequestIP(requestIPAddr *net.IP, req *http.Req
277277
if !ok {
278278
entry, err = a.createNewIPEntry(req, ipAddressString)
279279
if err != nil && !(os.IsTimeout(err) && a.ignoreAPITimeout) {
280+
a.infoLogger.Printf("%s: request denied [%s] due to error: %s", a.name, requestIPAddr, err)
280281
return false, ""
281282
} else if os.IsTimeout(err) && a.ignoreAPITimeout {
282283
a.infoLogger.Printf("%s: request allowed [%s] due to API timeout", a.name, requestIPAddr)
@@ -295,16 +296,18 @@ func (a *GeoBlock) allowDenyCachedRequestIP(requestIPAddr *net.IP, req *http.Req
295296
if time.Since(entry.Timestamp).Hours() >= numberOfHoursInMonth && a.forceMonthlyUpdate {
296297
entry, err = a.createNewIPEntry(req, ipAddressString)
297298
if err != nil {
299+
a.infoLogger.Printf("%s: request denied [%s] due to error: %s", a.name, requestIPAddr, err)
298300
return false, ""
299301
}
300302
}
301303

302304
// check if we are in black/white-list mode and allow/deny based on country code
303-
isAllowed := (stringInSlice(entry.Country, a.countries) != a.blackListMode) ||
304-
(entry.Country == unknownCountryCode && a.allowUnknownCountries)
305+
isUnknownCountry := entry.Country == unknownCountryCode
306+
isCountryAllowed := stringInSlice(entry.Country, a.countries) != a.blackListMode
307+
isAllowed := isCountryAllowed || (isUnknownCountry && a.allowUnknownCountries)
305308

306309
if !isAllowed {
307-
a.infoLogger.Printf("%s: request denied [%s] for country [%s]", a.name, requestIPAddr, entry.Country)
310+
a.infoLogger.Printf("%s: request denied [%s] for country [%s] due to: unknown country=%t and allow unknown countries=%t or the country is not allowed=%t", a.name, requestIPAddr, entry.Country, isUnknownCountry, a.allowUnknownCountries, isCountryAllowed)
308311
return false, entry.Country
309312
}
310313

0 commit comments

Comments
 (0)