Skip to content

Commit

Permalink
updated validation error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Nov 14, 2023
1 parent 17ab5bf commit 803e9f0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions primaryHandler.go
Expand Up @@ -569,13 +569,26 @@ func ValidateWRP(logger *zap.Logger) func(http.Handler) http.Handler {

if msg, ok := wrpcontext.GetMessage(r.Context()); ok {
var err error
var failureError error
var warningErrors error

validators := wrp.SpecValidators()

Check warning on line 575 in primaryHandler.go

View check run for this annotation

Codecov / codecov/patch

primaryHandler.go#L572-L575

Added lines #L572 - L575 were not covered by tests
for _, v := range validators {
err = multierr.Append(err, v.Validate(*msg))
err = v.Validate(*msg)
if errors.Is(err, wrp.ErrorInvalidMessageEncoding.Err) || errors.Is(err, wrp.ErrorInvalidMessageType.Err) {
failureError = multierr.Append(failureError, err)
} else if errors.Is(err, wrp.ErrorInvalidDestination.Err) || errors.Is(err, wrp.ErrorInvalidSource.Err) {
warningErrors = multierr.Append(warningErrors, err)
}

Check warning on line 582 in primaryHandler.go

View check run for this annotation

Codecov / codecov/patch

primaryHandler.go#L577-L582

Added lines #L577 - L582 were not covered by tests
}

if warningErrors != nil {
logger.Warn("WRP message validation failures found", zap.Error(err))
}

Check warning on line 587 in primaryHandler.go

View check run for this annotation

Codecov / codecov/patch

primaryHandler.go#L585-L587

Added lines #L585 - L587 were not covered by tests

if errors.Is(err, wrp.ErrorInvalidMessageEncoding.Err) || errors.Is(err, wrp.ErrorInvalidMessageType.Err) {
if failureError != nil {
logger.Error("WRP message validation failures found", zap.Error(failureError))

Check warning on line 591 in primaryHandler.go

View check run for this annotation

Codecov / codecov/patch

primaryHandler.go#L589-L591

Added lines #L589 - L591 were not covered by tests
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(
Expand All @@ -584,8 +597,6 @@ func ValidateWRP(logger *zap.Logger) func(http.Handler) http.Handler {
http.StatusBadRequest,
fmt.Sprintf("failed to validate WRP message: %s", err))

Check warning on line 598 in primaryHandler.go

View check run for this annotation

Codecov / codecov/patch

primaryHandler.go#L598

Added line #L598 was not covered by tests
return
} else if errors.Is(err, wrp.ErrorInvalidDestination.Err) || errors.Is(err, wrp.ErrorInvalidSource.Err) {
logger.Warn("WRP message validation failures found", zap.Error(err))
}
}

Expand Down

0 comments on commit 803e9f0

Please sign in to comment.