chore: common err resp log

This commit is contained in:
Noah Hsu
2022-06-28 18:12:53 +08:00
parent 67bc66fedf
commit d1efec4539
10 changed files with 68 additions and 56 deletions

View File

@ -1,15 +1,20 @@
package common
import (
"github.com/alist-org/alist/v3/cmd/args"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
// ErrorResp is used to return error response
// @param nl: if true, don't log error
func ErrorResp(c *gin.Context, err error, code int, nl ...bool) {
if len(nl) == 0 || !nl[0] {
log.Errorf("%+v", err)
// @param l: if true, log error
func ErrorResp(c *gin.Context, err error, code int, l ...bool) {
if len(l) > 0 && l[0] {
if args.Debug || args.Dev {
log.Errorf("%+v", err)
} else {
log.Errorf("%v", err)
}
}
c.JSON(200, Resp{
Code: code,