From 8c988efa08e13370bcfe70a760733814dbe22fab Mon Sep 17 00:00:00 2001 From: Sergio de Carvalho Date: Fri, 9 Dec 2022 23:31:48 +0000 Subject: [PATCH] feat: warn when session cookie may be expired --- CONTRIBUTING.md | 2 -- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 15 ++++++++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1c338f9..b640009 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/Cargo.lock b/Cargo.lock index 93c0964..6270796 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,7 @@ dependencies = [ "exit-code", "html2md", "html2text", + "http", "log", "openssl", "regex", diff --git a/Cargo.toml b/Cargo.toml index d782421..5692566 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/main.rs b/src/main.rs index 808ff15..cc113fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -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, };