Skip to content

Commit

Permalink
refactor: modified FieldError's Error type
Browse files Browse the repository at this point in the history
* Modified FieldError's Error type
* It's Error(), not String()...
  • Loading branch information
ralvarezdev committed Jan 13, 2025
1 parent ee0f409 commit aec6c19
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions http/response/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type (
// FieldError struct
FieldError struct {
Field string
Err error
Err string
}
)

Expand Down Expand Up @@ -161,18 +161,17 @@ func NewErrorResponse(

// NewFieldError creates a new field error
func NewFieldError(
field string,
err error,
field, err string,
) *FieldError {
return &FieldError{
Field: field,
Err: err,
}
}

// String returns the field error as a string
func (f *FieldError) String() string {
return f.Err.Error()
// Error returns the field error as a string
func (f *FieldError) Error() string {
return f.Err
}

// NewFieldErrorsBodyData creates a new field errors body data
Expand All @@ -192,12 +191,12 @@ func NewFieldErrorsBodyData(
// Check if the field name exists in the map
if _, ok := fieldErrorsMap[fieldError.Field]; !ok {
// Initialize the field errors slice
fieldErrorsMap[fieldError.Field] = &[]string{fieldError.Err.Error()}
fieldErrorsMap[fieldError.Field] = &[]string{fieldError.Err}
} else {
// Append the error to the field errors slice
*fieldErrorsMap[fieldError.Field] = append(
*fieldErrorsMap[fieldError.Field],
fieldError.Err.Error(),
fieldError.Err,
)
}
}
Expand Down

0 comments on commit aec6c19

Please sign in to comment.