Files
nCovTrack-Backend/handler/errors.go
2022-05-04 20:06:21 +08:00

49 lines
1.3 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"
STATUS_OPERATION_FAILED = 410
OPERATION_FAILED = "operation failed"
)
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)
}
func OperationFailed(c *gin.Context) {
c.String(STATUS_OPERATION_FAILED, OPERATION_FAILED)
}