Skip to content

Commit

Permalink
feat: warn when session cookie may be expired
Browse files Browse the repository at this point in the history
  • Loading branch information
scarvalhojr committed Dec 9, 2022
1 parent ac64a64 commit 8c988ef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ In particular, the commit message should start with one of the following types:
- input-filename
- description-filename

- Detect when session cookie is expired (currently user gets a HTTP 500 error).

- Warn user if session file permissions allow reading by others.

- Add option to wait until the next puzzle unlocks with a countdown timer (for
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exit-code = "1.0"
env_logger = "0.10"
html2md = "0.2"
html2text = "0.4"
http = "0.2"
log = "0.4"
regex = "1.7"
reqwest = { version = "0.11", features = ["blocking"] }
Expand Down
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use args::*;
use clap::{crate_description, crate_name, Parser};
use env_logger::{Builder, Env};
use exit_code::*;
use http::StatusCode;
use log::{error, info, LevelFilter};
use std::process::exit;

Expand All @@ -29,7 +30,19 @@ fn main() {
AocError::MissingConfigDir => NO_INPUT,
AocError::SessionFileReadError { .. } => IO_ERROR,
AocError::InvalidSessionCookie { .. } => DATA_ERROR,
AocError::HttpRequestError { .. } => FAILURE,
AocError::HttpRequestError { source } => {
if let Some(StatusCode::INTERNAL_SERVER_ERROR) =
source.status()
{
// adventofcode.com returns HTTP 500 when session cookie
// is no longer valid
error!(
"🔔 Your session cookie may have expired, try \
logging in again"
);
}
FAILURE
}
AocError::AocResponseError => FAILURE,
AocError::FileWriteError { .. } => CANNOT_CREATE,
};
Expand Down

0 comments on commit 8c988ef

Please sign in to comment.