Skip to content

Commit

Permalink
fix: solved some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ralvarezdev committed Jan 14, 2025
1 parent a849e96 commit b805507
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
10 changes: 2 additions & 8 deletions http/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ package http

import (
"errors"
gojwtnethttp "github.com/ralvarezdev/go-jwt/net/http"
gonethttpresponse "github.com/ralvarezdev/go-net/http/response"
)

var (
ErrNilRequestBody = errors.New("request body cannot be nil")
ErrInDevelopment = errors.New("in development")
ErrInvalidAuthorizationHeader = gonethttpresponse.NewHeaderError(
gojwtnethttp.AuthorizationHeaderKey,
"invalid authorization header",
)
ErrNilRequestBody = errors.New("request body cannot be nil")
ErrInDevelopment = errors.New("in development")
)
20 changes: 8 additions & 12 deletions http/json/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ func bodyDecodeErrorHandler(
if fieldName != "" {
return encoder.Encode(
w,
gonethttpresponse.NewDebugFailResponse(
gonethttpresponse.NewRequestErrorsBodyData(
gonethttpresponse.NewFieldError(
fieldName,
fmt.Sprintf(
ErrFieldInvalidValue,
fieldTypeName,
fieldValue,
),
gonethttpresponse.NewFailResponseFromRequestError(
gonethttpresponse.NewFieldError(
fieldName,
fmt.Sprintf(
ErrFieldInvalidValue,
fieldTypeName,
fieldValue,
),
http.StatusBadRequest,
),
err,
nil,
http.StatusBadRequest,
),
)
}
Expand Down
10 changes: 9 additions & 1 deletion http/middleware/auth/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ package auth

import (
"errors"
gojwtnethttp "github.com/ralvarezdev/go-jwt/net/http"
gonethttpresponse "github.com/ralvarezdev/go-net/http/response"
"net/http"
)

var (
ErrNilAuthenticator = errors.New("authenticator cannot be nil")
ErrNilAuthenticator = errors.New("authenticator cannot be nil")
ErrInvalidAuthorizationHeader = gonethttpresponse.NewHeaderError(
gojwtnethttp.AuthorizationHeaderKey,
"invalid authorization header",
http.StatusUnauthorized,
)
)
3 changes: 1 addition & 2 deletions http/middleware/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
gojwtnethttpctx "github.com/ralvarezdev/go-jwt/net/http/context"
gojwtinterception "github.com/ralvarezdev/go-jwt/token/interception"
gojwtvalidator "github.com/ralvarezdev/go-jwt/token/validator"
gonethttp "github.com/ralvarezdev/go-net/http"
gonethttphandler "github.com/ralvarezdev/go-net/http/handler"
gonethttpjwtvalidator "github.com/ralvarezdev/go-net/http/jwt/validator"
"net/http"
Expand Down Expand Up @@ -61,7 +60,7 @@ func (m *Middleware) Authenticate(
if len(parts) < 2 || parts[0] != gojwt.BearerPrefix {
m.jwtValidatorFailHandler(
w,
gonethttp.ErrInvalidAuthorizationHeader,
ErrInvalidAuthorizationHeader,
)
return
}
Expand Down

0 comments on commit b805507

Please sign in to comment.