fix: issues
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
package errorx
|
package errorx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
"github.com/gofiber/fiber/v3/binder"
|
"github.com/gofiber/fiber/v3/binder"
|
||||||
"github.com/gofiber/utils/v2"
|
"github.com/gofiber/utils/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Middleware(c fiber.Ctx) error {
|
func Middleware(c fiber.Ctx) error {
|
||||||
@@ -90,7 +91,12 @@ func (r *Response) format() {
|
|||||||
|
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
msg := r.err.Error()
|
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)
|
r.from(RecordDuplicated)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user