error.go 562 B

12345678910111213141516171819202122232425
  1. package factory
  2. import (
  3. "github.com/go-playground/validator/v10"
  4. "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
  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. }