Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
fixed unauthorized error
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed May 15, 2017
1 parent eec41b4 commit 8f85c8a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// Version ...
const Version = "1.5.2"
const Version = "1.5.3"

// TokenExtractor is a function that takes a gear.Context as input and
// returns either a string token or an empty string. Default to:
Expand Down Expand Up @@ -91,7 +91,9 @@ func (a *Auth) New(ctx *gear.Context) (val interface{}, err error) {
// create a empty jwt.Claims
val = josejwt.Claims{}
if err == nil {
err = &gear.Error{Code: 401, Msg: "no token found"}
err = gear.ErrUnauthorized.WithMsg("no token found")
} else {
err = gear.ErrUnauthorized.From(err)
}
}
ctx.SetAny(a, val)
Expand Down
2 changes: 1 addition & 1 deletion auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestGearAuth(t *testing.T) {
assert.Nil(err)
assert.Equal(401, res.StatusCode)
body, _ := res.Text()
assert.Equal("no token found", body)
assert.Equal(`{"error":"Unauthorized","message":"no token found"}`, body)

a1 := New([]byte("wrong key"))
claims := jwt.Claims{}
Expand Down

0 comments on commit 8f85c8a

Please sign in to comment.