Browse Source

Ability for skipping error reporting by error message

Volodymyr Tkach 2 years ago
parent
commit
0a27b4283e
2 changed files with 21 additions and 3 deletions
  1. 4 2
      utils/http/logger/logger.go
  2. 17 1
      utils/http/logger/rollbar.go

+ 4 - 2
utils/http/logger/logger.go

@@ -12,7 +12,7 @@ import (
 
 func LogInternalError(err error) {
 	log.Printf("%s\n", err.Error())
-	if RollBarEnabled {
+	if RollBarEnabled && !RollBarSkipErrors.contain(err.Error()) {
 		rollbar.Error(err)
 	}
 }
@@ -42,7 +42,9 @@ func LogRequests(handler http.Handler) http.Handler {
 			ua,
 		)
 		if RollBarEnabled && !RollBarSkipStatusCodes.contain(nw.Status) {
-			rollbar.Error(r, nw.Status, nw.Size, string(nw.Content))
+			if !RollBarSkipErrors.contain(string(nw.Content)) {
+				rollbar.Error(r, nw.Status, nw.Size, string(nw.Content))
+			}
 		}
 	})
 }

+ 17 - 1
utils/http/logger/rollbar.go

@@ -1,6 +1,9 @@
 package logger
 
-import "net/http"
+import (
+	"net/http"
+	"strings"
+)
 
 var RollBarEnabled = false
 
@@ -22,3 +25,16 @@ func (r RollBarStatusCodes) contain(status int) bool {
 	}
 	return false
 }
+
+type RollBarErrors []string
+
+var RollBarSkipErrors = RollBarErrors{}
+
+func (r RollBarErrors) contain(str string) bool {
+	for _, v := range r {
+		if v == str || strings.Contains(str, v) {
+			return true
+		}
+	}
+	return false
+}