nginx-ui/internal/cosy/error.go
2024-04-30 10:11:51 +08:00

23 lines
475 B
Go

package cosy
import (
"errors"
"github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"gorm.io/gorm"
"net/http"
)
func errHandler(c *gin.Context, err error) {
logger.GetLogger().WithOptions(zap.AddCallerSkip(1)).Errorln(err)
if errors.Is(err, gorm.ErrRecordNotFound) {
c.JSON(http.StatusNotFound, gin.H{
"message": err.Error(),
})
return
}
c.JSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
})
}