Skip to content

Commit

Permalink
Fix expired session login redirect.
Browse files Browse the repository at this point in the history
When we switched to session based authentication from token based, we
introduced an undesired UX issue when a session expires. In summary,
when a session expires, the desired functionality is that the user will
be presented with a message indicating the expiration and prompted to
login in again.

While the first of these was occuring in the form of a formatted HTTP
error output the latter was not. Also, the form of the error was less
than desirable too.

Therefore, what we've done here is updated the error handling around
session expiration/unauthorized errors to prompt the user to login
again.  Also, we've taken the opporunity to clean up the error output of
other API errors as well such that it's presents the error. Use of
`HTTP_DEBUG` is still supported if the full HTTP error details is
necessary for debugging purposes.
  • Loading branch information
abrightwell committed Jul 26, 2024
1 parent 9dbc7e6 commit d9f45c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `cb firewall` deprecated in favor of `cb network`.

### Fixed
- Expired session handling not prompting for new login.
- `cb list` completion to include `--format`.

## [3.5.1] - 2024-05-09
Expand Down
11 changes: 3 additions & 8 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1006,14 +1006,9 @@ rescue e : CB::Program::Error

exit 1
rescue e : CB::Client::Error
if e.unauthorized?
# if PROG.ensure_token_still_good
# STDERR << "error".colorize.t_warn << ": Token had expired, but has been refreshed. Please try again.\n"
# exit 1
# end
end
STDERR.puts e
exit 2
STDERR << "error".colorize.red.bold << ": #{e.message}\n"
exit 2 unless e.unauthorized?
CB::Login.new.run
rescue e
capture_error e
exit 3
Expand Down

0 comments on commit d9f45c6

Please sign in to comment.