error.go 475 B

1234567891011121314151617181920212223
  1. package cosy
  2. import (
  3. "errors"
  4. "github.com/0xJacky/Nginx-UI/internal/logger"
  5. "github.com/gin-gonic/gin"
  6. "go.uber.org/zap"
  7. "gorm.io/gorm"
  8. "net/http"
  9. )
  10. func errHandler(c *gin.Context, err error) {
  11. logger.GetLogger().WithOptions(zap.AddCallerSkip(1)).Errorln(err)
  12. if errors.Is(err, gorm.ErrRecordNotFound) {
  13. c.JSON(http.StatusNotFound, gin.H{
  14. "message": err.Error(),
  15. })
  16. return
  17. }
  18. c.JSON(http.StatusInternalServerError, gin.H{
  19. "message": err.Error(),
  20. })
  21. }