mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Handle RecordNotFound error.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"nysoure/server/model"
|
||||
|
||||
"github.com/gofiber/fiber/v3/log"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
@@ -55,6 +56,12 @@ func ErrorHandler(c fiber.Ctx) error {
|
||||
Data: nil,
|
||||
Message: fiberErr.Message,
|
||||
})
|
||||
} else if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return c.Status(fiber.StatusNotFound).JSON(model.Response[any]{
|
||||
Success: false,
|
||||
Data: nil,
|
||||
Message: "Not found",
|
||||
})
|
||||
} else {
|
||||
var fiberErr *fiber.Error
|
||||
if errors.As(err, &fiberErr) {
|
||||
|
Reference in New Issue
Block a user