mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-10-03 13:59:52 +00:00
修改文件目录
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func CustomError(c *gin.Context) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
|
||||
if c.IsAborted() {
|
||||
c.Status(200)
|
||||
}
|
||||
switch errStr := err.(type) {
|
||||
case string:
|
||||
p := strings.Split(errStr, "#")
|
||||
if len(p) == 3 && p[0] == "CustomError" {
|
||||
statusCode, e := strconv.Atoi(p[1])
|
||||
if e != nil {
|
||||
break
|
||||
}
|
||||
c.Status(statusCode)
|
||||
fmt.Println(
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
"[ERROR]",
|
||||
c.Request.Method,
|
||||
c.Request.URL,
|
||||
statusCode,
|
||||
c.Request.RequestURI,
|
||||
c.ClientIP(),
|
||||
p[2],
|
||||
)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": statusCode,
|
||||
"msg": p[2],
|
||||
})
|
||||
}
|
||||
default:
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
c.Next()
|
||||
}
|
||||
Reference in New Issue
Block a user