diff --git a/auth.go b/auth.go index 07bc0d8..5cbcbe8 100644 --- a/auth.go +++ b/auth.go @@ -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: @@ -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) diff --git a/auth_test.go b/auth_test.go index fd1ee13..1ff856b 100644 --- a/auth_test.go +++ b/auth_test.go @@ -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{}