From bfcc1327d294c867c5700bc872baa9baee579fa9 Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 10 Sep 2025 20:25:20 +0800 Subject: [PATCH] fix: issues --- templates/project/app/errorx/error.go.tpl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/templates/project/app/errorx/error.go.tpl b/templates/project/app/errorx/error.go.tpl index 5568837..cd90c17 100644 --- a/templates/project/app/errorx/error.go.tpl +++ b/templates/project/app/errorx/error.go.tpl @@ -1,15 +1,16 @@ package errorx import ( + "errors" "fmt" "net/http" "runtime" - "strings" "github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3/binder" "github.com/gofiber/utils/v2" log "github.com/sirupsen/logrus" + "gorm.io/gorm" ) func Middleware(c fiber.Ctx) error { @@ -90,7 +91,12 @@ func (r *Response) format() { if r.err != nil { msg := r.err.Error() - if strings.Contains(msg, "duplicate key value") || strings.Contains(msg, "unique constraint") { + if errors.Is(r.err, gorm.ErrRecordNotFound) { + r.from(RecordNotExists) + return + } + + if errors.Is(r.err, gorm.ErrDuplicatedKey) { r.from(RecordDuplicated) return }