refactor: make the serverside error handling more robust

This commit is contained in:
Matouš Volf
2024-08-18 19:09:40 +02:00
parent a78f6bac94
commit 38be8af169
12 changed files with 301 additions and 43 deletions

View File

@ -3,10 +3,10 @@ use diesel::prelude::*;
use dotenvy::dotenv;
use std::env;
pub(crate) fn establish_database_connection() -> PgConnection {
pub(crate) fn establish_database_connection() -> ConnectionResult<PgConnection> {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let database_url =
env::var("DATABASE_URL").expect("The environment variable DATABASE_URL must be set.");
PgConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("error connecting to {}", database_url))
}