26 lines
440 B
Go
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
|
|
}
|