Skip to content

Commit

Permalink
feat: add Error Handler middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
slowhigh committed May 29, 2024
1 parent 1f9c422 commit 3e7a3fb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions infra/router/middleware/middleware.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package middleware

import (
"log/slog"
"net/http"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
Expand All @@ -13,3 +16,13 @@ func CorsHandler() gin.HandlerFunc {
AllowOrigins: []string{"*"},
})
}

func ErrorHandler(c *gin.Context) {
c.Next()

for _, err := range c.Errors {
slog.Error(err.Error())
}

c.JSON(http.StatusInternalServerError, "")
}

0 comments on commit 3e7a3fb

Please sign in to comment.