Skip to content

Commit 6bf892d

Browse files
committed
[BigCache] (*) Middleware error handling
1 parent 42bfe43 commit 6bf892d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bigcache.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func (bc *BigCacheClient) Middleware(hash hash.IHash) echo.MiddlewareFunc {
3939
token := c.Request().Header.Get(echo.HeaderAuthorization)
4040
key := hash.SHA512(token)
4141

42-
if val, err := bc.Get(key); err != nil {
42+
if _, err := bc.Get(key); (err != nil) || (err.Error() != "ErrEntryNotFound") {
4343
log.Printf("Can not get accesstoken from redis in redis middleware: %s", err.Error())
4444
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
45-
} else if val == "" {
45+
} else {
4646
return c.NoContent(http.StatusUnauthorized)
4747
}
4848

@@ -65,7 +65,7 @@ func (bc *BigCacheClient) Set(key string, value interface{}, expire time.Duratio
6565
func (bc *BigCacheClient) Get(key string) (interface{}, error) {
6666
b, err := bc.Client.Get(key)
6767
if err != nil {
68-
return nil, nil
68+
return nil, err
6969
}
7070

7171
var value interface{}

0 commit comments

Comments
 (0)