viper-app/internal/server/common/error.go
2023-02-03 16:18:31 +08:00

26 lines
440 B
Go

package common
import (
"github.com/gin-gonic/gin"
"net/http"
)
func ErrorReqIn(c *gin.Context, err error) {
c.JSON(http.StatusBadRequest, errHandler(err))
}
func ErrorOpt(c *gin.Context, err error) {
c.JSON(http.StatusInternalServerError, errHandler(err))
}
func errHandler(err error) gin.H {
var data gin.H
if err != nil {
data = gin.H{
"msg": err.Error(),
"code": http.StatusInternalServerError,
}
}
return data
}