updates to mock content and contract view implementation

This commit is contained in:
Timur Gordon
2025-04-23 03:52:11 +02:00
parent 6060831f61
commit b56f1cbc30
9 changed files with 1453 additions and 644 deletions

View File

@@ -1,6 +1,7 @@
use actix_web::{error, Error, HttpResponse};
use chrono::{DateTime, Utc};
use tera::{self, Context, Function, Tera, Value};
use std::error::Error as StdError;
// Export modules
pub mod redis_service;
@@ -137,39 +138,58 @@ pub fn render_template(
Ok(HttpResponse::Ok().content_type("text/html").body(content))
},
Err(e) => {
// Log the error
// Log the error with more details
println!("DEBUG: Template rendering error for {}: {}", template_name, e);
println!("DEBUG: Error details: {:?}", e);
// Print the error cause chain for better debugging
let mut current_error: Option<&dyn StdError> = Some(&e);
let mut error_chain = Vec::new();
while let Some(error) = current_error {
error_chain.push(format!("{}", error));
current_error = error.source();
}
println!("DEBUG: Error chain: {:?}", error_chain);
// Log the error
log::error!("Template rendering error: {}", e);
// Create a simple error response instead of trying to render the error template
// Create a simple error response with more detailed information
let error_html = format!(
r#"<!DOCTYPE html>
<html>
<head>
<title>Template Error</title>
<style>
body {{ font-family: Arial, sans-serif; margin: 40px; }}
.error-container {{ border: 1px solid #dc3545; padding: 20px; border-radius: 5px; }}
h1 {{ color: #dc3545; }}
pre {{ background-color: #f8f9fa; padding: 15px; border-radius: 5px; overflow-x: auto; }}
body {{ font-family: Arial, sans-serif; margin: 40px; line-height: 1.6; }}
.error-container {{ border: 1px solid #f5c6cb; background-color: #f8d7da; padding: 20px; border-radius: 5px; }}
.error-title {{ color: #721c24; }}
.error-details {{ background-color: #f8f9fa; padding: 15px; border-radius: 5px; margin-top: 20px; }}
pre {{ background-color: #f1f1f1; padding: 10px; overflow: auto; }}
</style>
</head>
<body>
<div class="error-container">
<h1>Template Rendering Error</h1>
<p><strong>Template:</strong> {}</p>
<p><strong>Error:</strong></p>
<pre>{}</pre>
<p><a href="/">Return to Home</a></p>
<h1 class="error-title">Template Rendering Error</h1>
<p>There was an error rendering the template: <strong>{}</strong></p>
<div class="error-details">
<h3>Error Details:</h3>
<pre>{}</pre>
<h3>Error Chain:</h3>
<pre>{}</pre>
</div>
</div>
</body>
</html>"#,
template_name,
e
e,
error_chain.join("\n")
);
println!("DEBUG: Returning simple error page");
Ok(HttpResponse::InternalServerError()
.content_type("text/html")
.body(error_html))