Skip to main content

rustify_licensing/core/
error.rs

1//! The load-bearing distinction in the whole system: was the "no" *authoritative*
2//! (lock now, ignore grace) or *transient* (honor the offline grace window)?
3
4use std::fmt;
5
6/// Why a license check couldn't reach a positive verdict. The distinction decides
7/// whether we honor the offline grace window or **fail closed**.
8///
9/// A subtle failure mode to avoid: treating *all* errors as "offline" — a wrong-account or
10/// revoked license then silently rode the grace window. Mapping authoritative 4xx
11/// answers to [`CheckErr::Denied`] (no grace) is what fixes that.
12#[derive(Debug, Clone)]
13pub enum CheckErr {
14    /// Authoritative rejection (4xx: wrong account, unauthorized, bad request) — the
15    /// server answered "no". Lock; do **not** ride offline grace.
16    Denied(String),
17    /// Transient connectivity issue (network error, timeout, 429/5xx, or an ambiguous
18    /// non-JSON body — e.g. a captive portal). Honor the offline grace window.
19    Offline(String),
20}
21
22impl fmt::Display for CheckErr {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            CheckErr::Denied(s) | CheckErr::Offline(s) => write!(f, "{s}"),
26        }
27    }
28}
29
30impl std::error::Error for CheckErr {}