Skip to content

Commit b805507

Browse files
committed
fix: solved some bugs
1 parent a849e96 commit b805507

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

http/errors.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ package http
22

33
import (
44
"errors"
5-
gojwtnethttp "github.com/ralvarezdev/go-jwt/net/http"
6-
gonethttpresponse "github.com/ralvarezdev/go-net/http/response"
75
)
86

97
var (
10-
ErrNilRequestBody = errors.New("request body cannot be nil")
11-
ErrInDevelopment = errors.New("in development")
12-
ErrInvalidAuthorizationHeader = gonethttpresponse.NewHeaderError(
13-
gojwtnethttp.AuthorizationHeaderKey,
14-
"invalid authorization header",
15-
)
8+
ErrNilRequestBody = errors.New("request body cannot be nil")
9+
ErrInDevelopment = errors.New("in development")
1610
)

http/json/body.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,16 @@ func bodyDecodeErrorHandler(
3131
if fieldName != "" {
3232
return encoder.Encode(
3333
w,
34-
gonethttpresponse.NewDebugFailResponse(
35-
gonethttpresponse.NewRequestErrorsBodyData(
36-
gonethttpresponse.NewFieldError(
37-
fieldName,
38-
fmt.Sprintf(
39-
ErrFieldInvalidValue,
40-
fieldTypeName,
41-
fieldValue,
42-
),
34+
gonethttpresponse.NewFailResponseFromRequestError(
35+
gonethttpresponse.NewFieldError(
36+
fieldName,
37+
fmt.Sprintf(
38+
ErrFieldInvalidValue,
39+
fieldTypeName,
40+
fieldValue,
4341
),
42+
http.StatusBadRequest,
4443
),
45-
err,
46-
nil,
47-
http.StatusBadRequest,
4844
),
4945
)
5046
}

http/middleware/auth/errors.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ package auth
22

33
import (
44
"errors"
5+
gojwtnethttp "github.com/ralvarezdev/go-jwt/net/http"
6+
gonethttpresponse "github.com/ralvarezdev/go-net/http/response"
7+
"net/http"
58
)
69

710
var (
8-
ErrNilAuthenticator = errors.New("authenticator cannot be nil")
11+
ErrNilAuthenticator = errors.New("authenticator cannot be nil")
12+
ErrInvalidAuthorizationHeader = gonethttpresponse.NewHeaderError(
13+
gojwtnethttp.AuthorizationHeaderKey,
14+
"invalid authorization header",
15+
http.StatusUnauthorized,
16+
)
917
)

http/middleware/auth/middleware.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
gojwtnethttpctx "github.com/ralvarezdev/go-jwt/net/http/context"
77
gojwtinterception "github.com/ralvarezdev/go-jwt/token/interception"
88
gojwtvalidator "github.com/ralvarezdev/go-jwt/token/validator"
9-
gonethttp "github.com/ralvarezdev/go-net/http"
109
gonethttphandler "github.com/ralvarezdev/go-net/http/handler"
1110
gonethttpjwtvalidator "github.com/ralvarezdev/go-net/http/jwt/validator"
1211
"net/http"
@@ -61,7 +60,7 @@ func (m *Middleware) Authenticate(
6160
if len(parts) < 2 || parts[0] != gojwt.BearerPrefix {
6261
m.jwtValidatorFailHandler(
6362
w,
64-
gonethttp.ErrInvalidAuthorizationHeader,
63+
ErrInvalidAuthorizationHeader,
6564
)
6665
return
6766
}

0 commit comments

Comments
 (0)