1
0
mirror of https://github.com/actix/actix-website synced 2024-11-24 00:41:07 +01:00

fix(ex-database): place pool get in web::block (#290)

This commit is contained in:
Raphael C 2022-10-07 19:12:51 +02:00 committed by GitHub
parent 52ba8ea777
commit 2bc48c18c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,14 +49,15 @@ async fn main() -> io::Result<()> {
async fn index(pool: web::Data<DbPool>, name: web::Path<(String)>) -> impl Responder {
let name = name.into_inner();
let conn = pool.get().expect("couldn't get db connection from pool");
let user = web::block(move || actions::insert_new_user(&conn, &user))
let user = web::block(move || {
let conn = pool.get().expect("couldn't get db connection from pool");
actions::insert_new_user(&conn, &user)
.await
.map_err(|e| {
eprintln!("{}", e);
HttpResponse::InternalServerError().finish()
})?;
}
})?;
Ok(HttpResponse::Ok().json(user))
}