Skip to content

Commit

Permalink
refactor: status code >= 500 is treated as an error
Browse files Browse the repository at this point in the history
  • Loading branch information
fufuok committed Feb 21, 2024
1 parent ee225b2 commit f5c25b3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion web/fiber/middleware/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func HTTPCounter(name string) fiber.Handler {

err = c.Next()

if err != nil || c.Response().StatusCode() >= fiber.StatusBadRequest {
if err != nil || c.Response().StatusCode() >= fiber.StatusInternalServerError {
counter.Err.Add(1)
} else {
counter.OK.Add(1)
Expand Down
3 changes: 2 additions & 1 deletion web/gin/middleware/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"fmt"
"net/http"
"sync/atomic"
"time"

Expand Down Expand Up @@ -36,7 +37,7 @@ func HTTPCounter(name string) gin.HandlerFunc {

c.Next()

if len(c.Errors) > 0 || c.Writer.Status() >= 400 {
if len(c.Errors) > 0 || c.Writer.Status() >= http.StatusInternalServerError {
counter.Err.Add(1)
} else {
counter.OK.Add(1)
Expand Down

0 comments on commit f5c25b3

Please sign in to comment.