more debug
This commit is contained in:
1 parent
02d76d31ea
commit
0fd76042f0
2 files changed
+46
-10
No files matched your search
+3
-3
@@ -7,8 +7,8 @@ publish = ["gitea"]
|
||||
[dependencies]
|
||||
actix-cors = "0.7"
|
||||
actix-web = "4"
|
||||
chrono = "0.4.41"
|
||||
fancy-regex = "0.14.0"
|
||||
icalendar = "0.16.13"
|
||||
chrono = "0.4"
|
||||
fancy-regex = "0.14"
|
||||
icalendar = "0.16"
|
||||
reqwest = {version = "0.12", features = ["blocking"]}
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
+43
-7
@@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, error::Error as _};
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_web::{App, HttpRequest, HttpResponse, HttpServer, Responder, get, http::header, web};
|
||||
@@ -27,19 +27,48 @@ async fn filtered_ics(
|
||||
|
||||
let now = **now;
|
||||
let client = Client::new();
|
||||
let ics_url = query.get("url").map_or(ICS_URL, String::as_str);
|
||||
let ics_url = query.get("url").map_or(ICS_URL, |d| {
|
||||
println!("ooh! url query from {d} idk if its good");
|
||||
d.as_str()
|
||||
});
|
||||
|
||||
// Fetch the .ics content
|
||||
let response = match client.get(ics_url).send().await {
|
||||
Ok(resp) => resp,
|
||||
Err(e) => return HttpResponse::BadGateway().body(format!("Failed to fetch ICS file: {e}")),
|
||||
Err(e) => {
|
||||
eprintln!("rq failed: {e}");
|
||||
if e.is_timeout() {
|
||||
return HttpResponse::GatewayTimeout()
|
||||
.body("Request timed out when fetching ICS file.");
|
||||
} else if e.is_connect() {
|
||||
return HttpResponse::BadGateway()
|
||||
.body("Failed to connect to the ICS server (maybe blocked or DNS issue).");
|
||||
} else if e.is_status() {
|
||||
return HttpResponse::BadGateway().body(format!(
|
||||
"ICS server returned error status: {}",
|
||||
e.status().unwrap() // is_status checked
|
||||
));
|
||||
} else if e.is_request() {
|
||||
return HttpResponse::BadRequest().body("Malformed request to ICS server.");
|
||||
} else {
|
||||
// Print error chain for debugging
|
||||
let mut source = e.source();
|
||||
while let Some(s) = source {
|
||||
eprintln!("caused by: {s}");
|
||||
source = s.source();
|
||||
}
|
||||
return HttpResponse::BadGateway().body(format!("Failed to fetch ICS file: {e}"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let body = match response.text().await {
|
||||
Ok(text) => text,
|
||||
Err(e) => {
|
||||
return HttpResponse::InternalServerError()
|
||||
.body(format!("Failed to read response body: {e}"));
|
||||
eprintln!("full body read failed: {e}");
|
||||
return HttpResponse::InternalServerError().body(format!(
|
||||
"Failed to read response body (connection dropped or invalid encoding?): {e}"
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -47,11 +76,16 @@ async fn filtered_ics(
|
||||
let regex_rules = match query.get("regex") {
|
||||
Some(rule) => match Regex::new(rule) {
|
||||
Ok(reg_mc) => Some(reg_mc),
|
||||
Err(e) => return HttpResponse::BadRequest().body(format!("Invalid regex rule: {e}")),
|
||||
Err(e) => {
|
||||
eprintln!("request regex is ass: {e}");
|
||||
return HttpResponse::BadRequest().body(format!("Invalid regex rule: {e}"));
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
if let Some(real) = ®ex_rules {
|
||||
println!("there is a regex rule and it is {}", real.as_str())
|
||||
};
|
||||
// Do the CPU-heavy stuff on another thread
|
||||
let block_task = tokio::task::spawn_blocking(move || -> Result<String, String> {
|
||||
let calendar = body.parse::<Calendar>()?;
|
||||
@@ -76,9 +110,11 @@ async fn filtered_ics(
|
||||
.content_type("text/calendar")
|
||||
.body(ics_output),
|
||||
Ok(Err(e)) => {
|
||||
eprintln!("parse err {e}");
|
||||
HttpResponse::InternalServerError().body(format!("Failed to process ICS file: {e}"))
|
||||
}
|
||||
Err(join_err) => {
|
||||
eprintln!("insane cooked thread err {join_err}");
|
||||
HttpResponse::InternalServerError().body(format!("Blocking thread failed: {join_err}"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user