register redirect failure as global

This commit is contained in:
yggverse 2025-01-15 05:22:21 +02:00
parent e48d425672
commit 8091dd6ace
3 changed files with 15 additions and 11 deletions

View File

@ -81,7 +81,7 @@ impl Client {
// * this condition just to make sure that client will never stuck by driver implementation issue
if self.redirect.count() > redirect::LIMIT {
self.status
.replace(Status::failure_redirect_limit(redirect::LIMIT));
.replace(Status::failure_redirect_limit(redirect::LIMIT, true));
// @TODO return;
}
}

View File

@ -34,10 +34,10 @@ impl Status {
}
/// Create new `Self::Failure` as `Failure::RedirectLimit`
pub fn failure_redirect_limit(count: usize) -> Self {
pub fn failure_redirect_limit(count: usize, is_global: bool) -> Self {
Self::Failure {
event: now(),
failure: Failure::redirect_limit(count),
failure: Failure::redirect_limit(count, is_global),
}
}

View File

@ -4,26 +4,30 @@ use std::fmt::{Display, Formatter, Result};
/// Local `Failure` status for `Client`
pub enum Failure {
/// Redirection count limit reached by protocol driver or global settings
RedirectLimit { count: usize },
RedirectLimit { count: usize, is_global: bool },
}
impl Failure {
// Constructors
/// Create new `Self::RedirectLimit`
pub fn redirect_limit(count: usize) -> Self {
Self::RedirectLimit { count }
pub fn redirect_limit(count: usize, is_global: bool) -> Self {
Self::RedirectLimit { count, is_global }
}
}
impl Display for Failure {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::RedirectLimit { count } => {
write!(
f,
"Redirection limit ({count}) reached by protocol driver or global settings"
)
Self::RedirectLimit { count, is_global } => {
if *is_global {
write!(f, "Redirection limit ({count}) reached by global settings")
} else {
write!(
f,
"Redirection limit ({count}) reached by protocol restrictions"
)
}
}
}
}