🍱 add more error context

This commit is contained in:
Max Lerebourg
2022-11-20 12:29:00 +01:00
parent 953e9f6bf4
commit 1dc50a8a8c
+5 -4
View File
@@ -154,13 +154,13 @@ func (bouncer *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// Here we check for the trusted IPs in the customHeader // Here we check for the trusted IPs in the customHeader
remoteIP, err := ip.GetRemoteIP(req, bouncer.serverPoolStrategy, bouncer.customHeader) remoteIP, err := ip.GetRemoteIP(req, bouncer.serverPoolStrategy, bouncer.customHeader)
if err != nil { if err != nil {
logger.Error(fmt.Sprintf("ServeHTTP ip:%s %s", remoteIP, err.Error())) logger.Error(fmt.Sprintf("ServeHTTP:getRemoteIp ip:%s %s", remoteIP, err.Error()))
rw.WriteHeader(http.StatusForbidden) rw.WriteHeader(http.StatusForbidden)
return return
} }
isTrusted, err := bouncer.clientPoolStrategy.Checker.Contains(remoteIP) isTrusted, err := bouncer.clientPoolStrategy.Checker.Contains(remoteIP)
if err != nil { if err != nil {
logger.Error(err.Error()) logger.Error(fmt.Sprintf("ServeHTTP:checkerContains ip:%s %s", remoteIP, err.Error()))
rw.WriteHeader(http.StatusForbidden) rw.WriteHeader(http.StatusForbidden)
return return
} }
@@ -175,7 +175,7 @@ func (bouncer *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if bouncer.crowdsecMode != noneMode { if bouncer.crowdsecMode != noneMode {
isBanned, err := cache.GetDecision(remoteIP) isBanned, err := cache.GetDecision(remoteIP)
if err != nil { if err != nil {
logger.Debug(err.Error()) logger.Debug(fmt.Sprintf("ServeHTTP:getDecision ip:%s %s", remoteIP, err.Error()))
if err.Error() == simpleredis.RedisUnreachable { if err.Error() == simpleredis.RedisUnreachable {
rw.WriteHeader(http.StatusForbidden) rw.WriteHeader(http.StatusForbidden)
return return
@@ -194,6 +194,7 @@ func (bouncer *Bouncer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// Right here if we cannot join the stream we forbid the request to go on. // Right here if we cannot join the stream we forbid the request to go on.
if bouncer.crowdsecMode == streamMode { if bouncer.crowdsecMode == streamMode {
if isCrowdsecStreamHealthy { if isCrowdsecStreamHealthy {
logger.Error(fmt.Sprintf("ServeHTTP:isCrowdsecStreamHealthy ip:%s", remoteIP))
rw.WriteHeader(http.StatusForbidden) rw.WriteHeader(http.StatusForbidden)
} else { } else {
bouncer.next.ServeHTTP(rw, req) bouncer.next.ServeHTTP(rw, req)
@@ -280,7 +281,7 @@ func handleNoStreamCache(bouncer *Bouncer, remoteIP string) error {
var decisions []Decision var decisions []Decision
err = json.Unmarshal(body, &decisions) err = json.Unmarshal(body, &decisions)
if err != nil { if err != nil {
return fmt.Errorf("handleNoStreamCache:parseBody: %w", err) return fmt.Errorf("handleNoStreamCache:parseBody %w", err)
} }
if len(decisions) == 0 { if len(decisions) == 0 {
if isLiveMode { if isLiveMode {