code refactor
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
package response
|
||||
|
||||
import "github.com/gofiber/fiber/v3"
|
||||
|
||||
type Response[T any] struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
Items *T `json:"items,omitempty"`
|
||||
Count *int `json:"count,omitempty"`
|
||||
Message string `json:"message"`
|
||||
Items *T `json:"items"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
func Make[T any](c fiber.Ctx, status int, items *T, count *int, message string) Response[T] {
|
||||
c.Status(status)
|
||||
func Make[T any](items *T, count int, message string) Response[T] {
|
||||
return Response[T]{
|
||||
Message: message,
|
||||
Items: items,
|
||||
|
||||
@@ -38,7 +38,7 @@ var (
|
||||
ErrVerificationTokenExpired = errors.New("verification token has expired")
|
||||
|
||||
// Typed errors for product description handler
|
||||
ErrBadAttribute = errors.New("bad attribute")
|
||||
ErrBadAttribute = errors.New("bad or missing attribute value in header")
|
||||
ErrBadField = errors.New("this field can not be updated")
|
||||
ErrInvalidXHTML = errors.New("text is not in xhtml format")
|
||||
ErrAIResponseFail = errors.New("AI responded with failure")
|
||||
@@ -119,9 +119,9 @@ func GetErrorCode(c fiber.Ctx, err error) string {
|
||||
case errors.Is(err, ErrInvalidXHTML):
|
||||
return i18n.T_(c, "error.err_invalid_html")
|
||||
case errors.Is(err, ErrAIResponseFail):
|
||||
return i18n.T_(c, "error.err_openai_response_fail")
|
||||
return i18n.T_(c, "error.err_ai_response_fail")
|
||||
case errors.Is(err, ErrAIBadOutput):
|
||||
return i18n.T_(c, "error.err_openai_bad_output")
|
||||
return i18n.T_(c, "error.err_ai_bad_output")
|
||||
|
||||
default:
|
||||
return i18n.T_(c, "error.err_internal_server_error")
|
||||
Reference in New Issue
Block a user