From 4a22068afbb11aca8b7ffbd36fb31e036e2641df Mon Sep 17 00:00:00 2001 From: jc <46619361+juancwu@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:12:15 -0500 Subject: [PATCH] update request validator to use APIError --- backend/internal/middleware/request_validator.go | 5 ++--- backend/internal/tests/request_validator_test.go | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/internal/middleware/request_validator.go b/backend/internal/middleware/request_validator.go index 9cf915cd..3ca10888 100644 --- a/backend/internal/middleware/request_validator.go +++ b/backend/internal/middleware/request_validator.go @@ -2,15 +2,14 @@ package middleware import ( "KonferCA/SPUR/db" + "KonferCA/SPUR/internal/v1/v1_common" "fmt" - "net/http" "os" "reflect" "regexp" "strings" "github.com/go-playground/validator/v10" - "github.com/labstack/echo/v4" "github.com/rs/zerolog/log" ) @@ -67,7 +66,7 @@ func (cv *CustomValidator) Validate(i interface{}) error { if err := cv.validator.Struct(i); err != nil { log.Error().Err(err).Msg("validation error") - return echo.NewHTTPError(http.StatusBadRequest, formatValidationErrors(err)) + return v1_common.NewValidationError(formatValidationErrors(err)) } return nil diff --git a/backend/internal/tests/request_validator_test.go b/backend/internal/tests/request_validator_test.go index 2d49a128..7b86dad7 100644 --- a/backend/internal/tests/request_validator_test.go +++ b/backend/internal/tests/request_validator_test.go @@ -2,6 +2,7 @@ package tests import ( "KonferCA/SPUR/internal/middleware" + "KonferCA/SPUR/internal/v1/v1_common" "os" "testing" @@ -169,7 +170,7 @@ func TestValidatorMiddleware(t *testing.T) { err := e.Validator.Validate(tc.input) if tc.expectedError { assert.Error(t, err) - httpErr, ok := err.(*echo.HTTPError) + httpErr, ok := err.(*v1_common.APIError) assert.True(t, ok) assert.Contains(t, httpErr.Message, tc.errorMessage) } else {