Skip to content

Commit

Permalink
platform: propagate errors (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianEffe authored Jul 3, 2024
2 parents cf90be5 + fee89af commit 65d377e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
},
helper::config::Config,
};
use anyhow::Result;
use axum::{
middleware,
routing::{get, post},
Expand All @@ -26,8 +27,8 @@ pub struct AppState<AS: AuthService> {
pub auth_service: AS,
}

pub async fn run(listener: TcpListener, config: Config) {
let postgres = PostgresDB::new(&config.database_url).await.unwrap(); //TODO: handle unwrap
pub async fn run(listener: TcpListener, config: Config) -> Result<()> {
let postgres = PostgresDB::new(&config.database_url).await?;
let redis = RedisCache::new(&config.redis_url);

let service = Service {
Expand All @@ -41,7 +42,9 @@ pub async fn run(listener: TcpListener, config: Config) {
});

let app = app(app_state);
axum::serve(listener, app).await.unwrap(); //TODO: handle unwrap
axum::serve(listener, app).await?;

Ok(())
}

fn app<AS: AuthService>(app_state: Arc<AppState<AS>>) -> Router {
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use anyhow::Result;
use authentication_service::{application::run, helper::config::Config};
use dotenv::dotenv;
use tokio::net::TcpListener;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

#[tokio::main]
async fn main() {
async fn main() -> Result<()> {
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.init();
Expand All @@ -14,5 +15,6 @@ async fn main() {
let config = Config::init();
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();

run(listener, config).await;
run(listener, config).await?;
Ok(())
}
2 changes: 1 addition & 1 deletion tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ async fn spawn_server() -> SocketAddr {
let config = Config::init();

tokio::spawn(async move {
run(listener, config).await;
run(listener, config).await.expect("Failed to run app");
});

address
Expand Down

0 comments on commit 65d377e

Please sign in to comment.