Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cofob committed Jul 28, 2024
1 parent 760e2d4 commit efe890a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum CrawlerError {
#[derive(Clone, Debug)]
pub enum CrawledInstanceStatus {
Ok(Duration),
#[allow(dead_code)]
InvalidStatusCode(StatusCode, Duration),
StringNotFound,
ConnectionError,
Expand Down
21 changes: 2 additions & 19 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ use askama::Template;
#[template(path = "error.html")]
pub struct ErrorTemplate<'a> {
pub detail: &'a str,
pub additional_data: &'a Option<serde_json::Value>,
pub status_code: StatusCode,
}

pub trait AdditionalErrorData {
fn additional_error_data(&self) -> Option<serde_json::Value>;
}

macro_rules! impl_api_error {
($err:ty, status => {$($variant:pat => $code:expr),+ $(,)?}) => {
impl actix_web::ResponseError for $err where $err: std::error::Error + 'static {
Expand All @@ -21,7 +16,7 @@ macro_rules! impl_api_error {

let detail = format!("{}", self);
let additional_data = None;
let error_page = crate::errors::ErrorTemplate { detail: &detail, additional_data: &additional_data, status_code: self.status_code() };
let error_page = crate::errors::ErrorTemplate { detail: &detail, status_code: self.status_code() };

actix_web::HttpResponse::build(self.status_code()).html(error_page.render().expect("failed to render error page"))
}
Expand All @@ -39,12 +34,10 @@ macro_rules! impl_api_error {
($err:ty, status => {$($variant:pat => $code:expr),+ $(,)?}$(,)? data => {$($add_variant:pat => $add_code:expr),+ $(,)?}) => {
impl actix_web::ResponseError for $err where $err: std::error::Error + 'static {
fn error_response(&self) -> actix_web::HttpResponse {
use crate::errors::AdditionalErrorData;
use askama::Template;

let detail = format!("{}", self);
let additional_data = self.additional_error_data();
let error_page = crate::errors::ErrorTemplate { detail: &detail, additional_data: &additional_data, status_code: self.status_code() };
let error_page = crate::errors::ErrorTemplate { detail: &detail, status_code: self.status_code() };

actix_web::HttpResponse::build(self.status_code()).content_type("text/html; charset=utf-8").body(error_page.render().expect("failed to render error page"))
}
Expand All @@ -57,16 +50,6 @@ macro_rules! impl_api_error {
}
}
}

impl crate::errors::AdditionalErrorData for $err {
fn additional_error_data(&self) -> Option<serde_json::Value> {
match self {
$(
$add_variant => $add_code,
)+
}
}
}
};
}
pub(crate) use impl_api_error;
2 changes: 1 addition & 1 deletion src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub fn get_redirect_instances<'a>(
Some(instances)
}

const MAX_DURATION: Duration = Duration::from_secs(std::u64::MAX);
const MAX_DURATION: Duration = Duration::from_secs(u64::MAX);

pub fn get_redirect_instance(
crawled_service: &CrawledService,
Expand Down

0 comments on commit efe890a

Please sign in to comment.