error.go 561 B

123456789101112131415161718192021222324
  1. package factory
  2. import (
  3. "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
  4. "github.com/go-playground/validator/v10"
  5. )
  6. func CreateValidateErrorResponse(errors error) []dto.ValidateErrorResponse {
  7. var res []dto.ValidateErrorResponse //nolint
  8. for _, err := range errors.(validator.ValidationErrors) {
  9. res = append(res, dto.ValidateErrorResponse{
  10. Field: err.StructNamespace(),
  11. Tag: err.Tag(),
  12. Value: err.Param(),
  13. })
  14. }
  15. return res
  16. }
  17. func CreateErrorResponse(err error) dto.ErrorResponse {
  18. return dto.ErrorResponse{Error: err.Error()}
  19. }