nezha/pkg/mygin/error.go

36 lines
546 B
Go
Raw Normal View History

2019-12-08 03:59:58 -05:00
package mygin
import (
"net/http"
"github.com/gin-gonic/gin"
2020-11-10 21:07:45 -05:00
"github.com/naiba/nezha/model"
2019-12-08 03:59:58 -05:00
)
type ErrInfo struct {
2021-08-10 08:13:17 -04:00
Code int
2019-12-08 03:59:58 -05:00
Title string
Msg string
Link string
Btn string
}
func ShowErrorPage(c *gin.Context, i ErrInfo, isPage bool) {
if isPage {
2021-08-10 08:13:17 -04:00
c.HTML(i.Code, "dashboard/error", CommonEnvironment(c, gin.H{
2019-12-08 03:59:58 -05:00
"Code": i.Code,
"Title": i.Title,
"Msg": i.Msg,
"Link": i.Link,
"Btn": i.Btn,
}))
} else {
c.JSON(http.StatusOK, model.Response{
Code: i.Code,
Message: i.Msg,
})
}
c.Abort()
}