Skip to content

Commit

Permalink
Add error log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 committed Oct 24, 2023
1 parent 80d267c commit fad7d2b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/service/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ func ParseJSONBytes(body []byte, obj interface{}) error {
if errors.As(err, &unmarshalTypeErr) {
return NewInvalidParameterError(unmarshalTypeErr.Field, fmt.Sprintf("must be %s", primitiveTypeToDisplayName(unmarshalTypeErr.Type)))
}

log.Error().Err(err).Msgf("service: invalid request body: ParseJSONBytes")
return NewInvalidRequestError("Invalid request body")
}
return nil
Expand All @@ -150,6 +152,7 @@ func ParseJSONBody(body io.Reader, obj interface{}) error {
return NewInvalidParameterError(unmarshalTypeErr.Field, fmt.Sprintf("must be %s", primitiveTypeToDisplayName(unmarshalTypeErr.Type)))
}
if !errors.Is(err, io.EOF) {
log.Error().Err(err).Msgf("service: invalid request body: ParseJSONBody")
return NewInvalidRequestError("Invalid request body")
}
}
Expand All @@ -162,6 +165,7 @@ func ValidateStruct(obj interface{}) error {
if err != nil {
var invalidValidationErr *validator.InvalidValidationError
if errors.As(err, &invalidValidationErr) {
log.Error().Err(err).Msgf("service: invalid request body: ValidateStruct")
return NewInvalidRequestError("Invalid request body")
}

Expand Down Expand Up @@ -213,6 +217,7 @@ func ValidateStruct(obj interface{}) error {
case "valid_inheritif":
return NewInvalidParameterError(fieldName, "can only be 'anyOf', 'allOf', 'noneOf', or a valid relation name")
default:
log.Error().Err(err).Msgf("service: invalid request body: ValidateStruct")
return NewInvalidRequestError("Invalid request body")
}
}
Expand Down

0 comments on commit fad7d2b

Please sign in to comment.