Categorize routes and refactor error handlers

This commit is contained in:
spikecodes 2021-01-13 19:53:52 -08:00
parent dd027bff4b
commit 0bf5576427
8 changed files with 100 additions and 91 deletions

View file

@ -42,7 +42,7 @@ pub async fn profile(req: HttpRequest) -> HttpResponse {
HttpResponse::Ok().content_type("text/html").body(s)
}
// If there is an error show error page
Err(msg) => error(msg.to_string()).await,
Err(msg) => error(msg).await,
}
}
@ -57,7 +57,7 @@ async fn user(name: &str) -> Result<User, &'static str> {
Ok(res) => {
// Grab creation date as unix timestamp
let created: i64 = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64;
// nested_val function used to parse JSON from Reddit APIs
let about = |item| res["data"]["subreddit"][item].as_str().unwrap_or_default().to_string();