|
@@ -65,12 +65,27 @@ async fn main() -> std::io::Result<()> {
|
65
|
65
|
let mut app = tide::new();
|
66
|
66
|
|
67
|
67
|
app.with(After(|mut res: Response| async {
|
68
|
|
- if let Some(err) = res.downcast_error::<async_std::io::Error>() {
|
69
|
|
- let mut context = Context::new();
|
70
|
|
- context.insert("error", &err.to_string());
|
71
|
|
- res.set_body(render("error.html", &context)?);
|
72
|
|
- res.set_status(StatusCode::InternalServerError);
|
73
|
|
- }
|
|
68
|
+ let mut context = Context::new();
|
|
69
|
+
|
|
70
|
+ match res.downcast_error::<async_std::io::Error>() {
|
|
71
|
+ Some(e) => {
|
|
72
|
+ context.insert("error", &e.to_string());
|
|
73
|
+ let status = if let ErrorKind::NotFound = e.kind() {
|
|
74
|
+ StatusCode::NotFound
|
|
75
|
+ } else {
|
|
76
|
+ StatusCode::InternalServerError
|
|
77
|
+ };
|
|
78
|
+ res.set_body(render("error.html", &context)?);
|
|
79
|
+ res.set_status(status);
|
|
80
|
+ }
|
|
81
|
+ None => match res.status() {
|
|
82
|
+ StatusCode::NotFound => {
|
|
83
|
+ context.insert("error", "Page not found");
|
|
84
|
+ res.set_body(render("error.html", &context)?);
|
|
85
|
+ }
|
|
86
|
+ _ => {}
|
|
87
|
+ },
|
|
88
|
+ };
|
74
|
89
|
|
75
|
90
|
Ok(res)
|
76
|
91
|
}));
|