Skip to content

Commit

Permalink
refactor: renamed NewSingleFieldErrorsBodyData function as NewFieldEr…
Browse files Browse the repository at this point in the history
…rorsBodyData
  • Loading branch information
ralvarezdev committed Jan 13, 2025
1 parent 812726a commit 83a7834
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion http/json/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func bodyDecodeErrorHandler(
return encoder.Encode(
w,
gonethttpresponse.NewDebugFailResponse(
gonethttpresponse.NewSingleFieldErrorsBodyData(
gonethttpresponse.NewFieldErrorsBodyData(
fieldName,
fmt.Errorf(
ErrFieldInvalidValue,
Expand Down
10 changes: 4 additions & 6 deletions http/jwt/validator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package validator
import (
gonethttpjson "github.com/ralvarezdev/go-net/http/json"
gonethttpresponse "github.com/ralvarezdev/go-net/http/response"
gostringsconvert "github.com/ralvarezdev/go-strings/convert"
"net/http"
)

Expand All @@ -20,14 +19,13 @@ func NewDefaultFailHandler(
}

return func(w http.ResponseWriter, err ...error) {
// Create the body map
var body = make(map[string]*[]string)
body["authorization"] = gostringsconvert.ErrorArrayToStringArray(&err)

// Encode the response
_ = jsonEncoder.Encode(
w, gonethttpresponse.NewFailResponse(
&body,
gonethttpresponse.NewFieldErrorsBodyData(
"authorization",
err...,
),
nil,
http.StatusUnauthorized,
),
Expand Down
8 changes: 4 additions & 4 deletions http/response/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func NewErrorResponse(
return NewDebugErrorResponse(err, err, data, errorCode, httpStatus)
}

// NewSingleFieldBodyData creates a new single field body data
func NewSingleFieldBodyData(
// NewFieldBodyData creates a new field body data
func NewFieldBodyData(
fieldName string,
fieldValue ...interface{},
) *map[string]interface{} {
Expand All @@ -164,8 +164,8 @@ func NewSingleFieldBodyData(
}
}

// NewSingleFieldErrorsBodyData creates a new single field errors body data
func NewSingleFieldErrorsBodyData(
// NewFieldErrorsBodyData creates a new single field errors body data
func NewFieldErrorsBodyData(
fieldName string,
fieldValue ...error,
) *map[string]*[]string {
Expand Down

0 comments on commit 83a7834

Please sign in to comment.