43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"nCovTrack-Backend/utils"
|
|
"net/http"
|
|
)
|
|
|
|
// This file is define some business error
|
|
|
|
const (
|
|
BAD_REQUEST = "Bad Request"
|
|
DATA_NOT_FOUND = "Data not Found"
|
|
STATUS_DATA_NOT_FOUND = 210
|
|
FORBIDDENT = "FORBIDDENT"
|
|
PAGE_NOT_FOUND = "404 page not found"
|
|
)
|
|
|
|
func RequestError(c *gin.Context, code int, data interface{}) {
|
|
utils.Error(c, http.StatusBadRequest, code, BAD_REQUEST, data)
|
|
}
|
|
|
|
func RequestErr(c *gin.Context, data interface{}) {
|
|
RequestError(c, http.StatusBadRequest, data)
|
|
}
|
|
func ServerError(c *gin.Context, code int, msg interface{}) {
|
|
utils.Err(c, http.StatusInternalServerError, code, msg)
|
|
}
|
|
|
|
func ServerErr(c *gin.Context, msg interface{}) {
|
|
ServerError(c, http.StatusInternalServerError, msg)
|
|
}
|
|
func DataNotFound(c *gin.Context, data interface{}) {
|
|
utils.Success(c, http.StatusOK, STATUS_DATA_NOT_FOUND, DATA_NOT_FOUND, data)
|
|
}
|
|
func Forbidden(c *gin.Context) {
|
|
utils.Err(c, http.StatusForbidden, http.StatusForbidden, FORBIDDENT)
|
|
}
|
|
|
|
func UrlNotFound(c *gin.Context) {
|
|
c.String(http.StatusNotFound, PAGE_NOT_FOUND)
|
|
}
|