Skip to content

Commit

Permalink
update request validator to use APIError
Browse files Browse the repository at this point in the history
  • Loading branch information
juancwu committed Dec 24, 2024
1 parent fb9be8b commit 4a22068
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions backend/internal/middleware/request_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion backend/internal/tests/request_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"KonferCA/SPUR/internal/middleware"
"KonferCA/SPUR/internal/v1/v1_common"
"os"
"testing"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4a22068

Please sign in to comment.