Skip to content

Commit

Permalink
fix: improve an error message for token invalidation (#1144)
Browse files Browse the repository at this point in the history
Make an error message for token invalidation more informative.
It wraps the `jwt` error so that `errors.Is()` recognizes it down stream.
The error message now reads "token is expired since it has been invalidated".
  • Loading branch information
hanyucui authored and determined-ci committed Mar 12, 2024
1 parent 60b4cbc commit a49cb5b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion master/pkg/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model
import (
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -191,7 +192,7 @@ func (e *ExternalSessions) Validate(claims *JWT) error {
d := time.Unix(claims.IssuedAt, 0)
v := e.Invalidations.GetInvalidatonTime(claims.UserID)
if d.Before(v) {
return jwt.ErrTokenExpired
return fmt.Errorf("%w since it has been invalidated", jwt.ErrTokenExpired)
}
return nil
}
Expand Down

0 comments on commit a49cb5b

Please sign in to comment.