Skip to content

Commit

Permalink
return token expiry message per case
Browse files Browse the repository at this point in the history
  • Loading branch information
aaperis committed Jan 23, 2025
1 parent 075731b commit ba984b1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,24 @@ func CheckTokenExpiration(accessToken string) error {
switch untilExp := time.Until(expiration); {
case untilExp < 0:
return fmt.Errorf("the provided access token has expired, please renew it")
case untilExp > 0 && untilExp < 24*time.Hour:
fmt.Fprintln(
case untilExp >= 0 && untilExp < 2*time.Hour:
fmt.Fprintf(
os.Stderr,
"The provided access token expires in",
time.Until(expiration).Truncate(time.Second),
"WARNING! The provided access token expires in only %d hours and %d minutes.\n",
int(untilExp.Hours()), int(untilExp.Minutes())-(int(untilExp.Hours())*60),
)
fmt.Fprintln(os.Stderr, "Consider renewing the token.")
case untilExp >= 2*time.Hour && untilExp < 24*time.Hour:
fmt.Fprintf(
os.Stderr,
"The provided access token expires in %d hours and %d minutes (at %d:%d).\n",
int(untilExp.Hours()), int(untilExp.Minutes())-(int(untilExp.Hours())*60), expiration.Hour(), expiration.Minute(),
)
fmt.Fprintln(os.Stderr, "Consider renewing the token.")
default:
fmt.Fprintln(
fmt.Fprintf(
os.Stderr,
"The provided access token expires in",
time.Until(expiration).Truncate(time.Second),
"The provided access token expires on %s.\n", expiration.Format("2006-01-02"),
)
}

Expand Down

0 comments on commit ba984b1

Please sign in to comment.