This commit is contained in:
spikecodes 2021-02-20 18:36:30 -08:00
parent 9cfab348eb
commit dd67b52199
No known key found for this signature in database
GPG key ID: 004CECFF9B463BCB
6 changed files with 9 additions and 14 deletions

View file

@ -246,12 +246,12 @@ async fn main() -> tide::Result<()> {
Ok("best") | Ok("hot") | Ok("new") | Ok("top") | Ok("rising") | Ok("controversial") => subreddit::page(req).await,
// Short link for post
Ok(id) if id.len() > 4 && id.len() < 7 => post::item(req).await,
_ => error("Nothing here".to_string()).await,
_ => error(req, "Nothing here".to_string()).await,
}
});
// Default service in case no routes match
app.at("*").get(|_| error("Nothing here".to_string()));
app.at("*").get(|req| error(req, "Nothing here".to_string()));
app.listen(listener).await?;
Ok(())

View file

@ -58,7 +58,7 @@ pub async fn item(req: Request<()>) -> tide::Result {
})
}
// If the Reddit API returns an error, exit and send error page to user
Err(msg) => error(msg).await,
Err(msg) => error(req, msg).await,
}
}

View file

@ -65,7 +65,7 @@ pub async fn find(req: Request<()>) -> tide::Result {
},
prefs: prefs(req),
}),
Err(msg) => error(msg).await,
Err(msg) => error(req, msg).await,
}
}

View file

@ -74,7 +74,7 @@ pub async fn page(req: Request<()>) -> tide::Result {
prefs: prefs(req),
})
}
Err(msg) => error(msg).await,
Err(msg) => error(req, msg).await,
}
}
@ -140,7 +140,7 @@ pub async fn wiki(req: Request<()>) -> tide::Result {
page,
prefs: prefs(req),
}),
Err(msg) => error(msg).await,
Err(msg) => error(req, msg).await,
}
}

View file

@ -41,7 +41,7 @@ pub async fn profile(req: Request<()>) -> tide::Result {
})
}
// If there is an error show error page
Err(msg) => error(msg).await,
Err(msg) => error(req, msg).await,
}
}

View file

@ -495,13 +495,8 @@ pub fn redirect(path: String) -> Response {
.build()
}
pub async fn error(msg: String) -> tide::Result {
let body = ErrorTemplate {
msg,
prefs: Preferences::default(),
}
.render()
.unwrap_or_default();
pub async fn error(req: Request<()>, msg: String) -> tide::Result {
let body = ErrorTemplate { msg, prefs: prefs(req) }.render().unwrap_or_default();
Ok(Response::builder(404).content_type("text/html").body(body).build())
}