|
@@ -9,6 +9,7 @@ extern crate diesel;
|
|
|
use std::io::Write;
|
|
|
|
|
|
use actix::prelude::*;
|
|
|
+use actix_http::error::ErrorInternalServerError;
|
|
|
use actix_http::{HttpService, KeepAlive};
|
|
|
use actix_service::map_config;
|
|
|
use actix_web::dev::{AppConfig, Body, Server};
|
|
@@ -23,7 +24,10 @@ use crate::db_pg::{PgConnection, RandomWorld, RandomWorlds, TellFortune, UpdateW
|
|
|
use crate::utils::{FortunesYarteTemplate, Writer};
|
|
|
|
|
|
async fn world_row(db: web::Data<Addr<PgConnection>>) -> Result<HttpResponse, Error> {
|
|
|
- let res = db.send(RandomWorld).await?;
|
|
|
+ let res = db
|
|
|
+ .send(RandomWorld)
|
|
|
+ .await
|
|
|
+ .map_err(|e| ErrorInternalServerError(e))?;
|
|
|
match res {
|
|
|
Ok(body) => {
|
|
|
let mut res = HttpResponse::with_body(StatusCode::OK, Body::Bytes(body));
|
|
@@ -45,7 +49,10 @@ async fn queries(
|
|
|
let q = utils::get_query_param(req.query_string());
|
|
|
|
|
|
// run sql queries
|
|
|
- let res = db.send(RandomWorlds(q)).await?;
|
|
|
+ let res = db
|
|
|
+ .send(RandomWorlds(q))
|
|
|
+ .await
|
|
|
+ .map_err(|e| ErrorInternalServerError(e))?;
|
|
|
if let Ok(worlds) = res {
|
|
|
let mut body = BytesMut::with_capacity(35 * worlds.len());
|
|
|
serde_json::to_writer(Writer(&mut body), &worlds).unwrap();
|
|
@@ -69,7 +76,10 @@ async fn updates(
|
|
|
let q = utils::get_query_param(req.query_string());
|
|
|
|
|
|
// update db
|
|
|
- let res = db.send(UpdateWorld(q)).await?;
|
|
|
+ let res = db
|
|
|
+ .send(UpdateWorld(q))
|
|
|
+ .await
|
|
|
+ .map_err(|e| ErrorInternalServerError(e))?;
|
|
|
if let Ok(worlds) = res {
|
|
|
let mut body = BytesMut::with_capacity(35 * worlds.len());
|
|
|
serde_json::to_writer(Writer(&mut body), &worlds).unwrap();
|
|
@@ -86,7 +96,10 @@ async fn updates(
|
|
|
}
|
|
|
|
|
|
async fn fortune(db: web::Data<Addr<PgConnection>>) -> Result<HttpResponse, Error> {
|
|
|
- let res = db.send(TellFortune).await?;
|
|
|
+ let res = db
|
|
|
+ .send(TellFortune)
|
|
|
+ .await
|
|
|
+ .map_err(|e| ErrorInternalServerError(e))?;
|
|
|
|
|
|
match res {
|
|
|
Ok(fortunes) => {
|