package main import ( "fmt" "safetwitch-backend/routes" "strings" "github.com/gin-gonic/gin" ) func ErrorHandler(c *gin.Context) { c.Next() err := c.Errors.Last() if err != nil { c.JSON(500, gin.H{ "status": "error", "message": err.Error(), }) } fmt.Println(err) } func notFoundHandler(context *gin.Context) { message := []string{"path", context.Request.URL.Path, "was not found."} context.JSON(404, gin.H{ "status": "error", "message": strings.Join(message, " "), }) } func main() { router := gin.Default() router.Use(ErrorHandler) routes.SetRoutes(router) router.NoRoute(notFoundHandler) router.Run() }