use potato::*;
mod test_async_error_handler {
use super::*;
#[potato::handle_error]
async fn custom_error_handler(req: &mut HttpRequest, err: anyhow::Error) -> HttpResponse {
let path = req.url_path.clone();
HttpResponse::text(format!("Custom error handler: {} at {}", err, path))
}
#[potato::http_get("/test_async_handler_error")]
async fn handler_with_error() -> anyhow::Result<HttpResponse> {
anyhow::bail!("Async handler error");
}
}
mod test_default_error_handler {
use super::*;
#[potato::http_get("/test_default_error")]
async fn handler_with_default_error() -> anyhow::Result<HttpResponse> {
anyhow::bail!("Default handler error");
}
}
#[tokio::test]
async fn test_error_handler_compilation() {
println!("Error handler macros compiled successfully");
let resp = HttpResponse::error("test error");
assert_eq!(resp.http_code, 500);
println!("Default error response works correctly");
}
#[tokio::test]
async fn test_error_handler_basic() {
let resp = HttpResponse::error("test error message");
assert_eq!(resp.http_code, 500);
let text_resp = HttpResponse::text("error test");
assert_eq!(text_resp.http_code, 200);
println!("Error response format test passed");
}