Skip to content

Commit b2c2851

Browse files
committed
refactor: improve structure
1 parent dce1c76 commit b2c2851

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

crates/shared/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use axum::{
55
};
66
use serde::Serialize;
77

8+
#[derive(Debug)]
89
pub struct AppError {
910
/// An error message.
1011
pub error: anyhow::Error,

src/main.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Duration;
2+
13
use axum::{
24
routing::{get, post},
35
Router,
@@ -9,26 +11,29 @@ use shutdown_signal::shutdown_signal;
911

1012
mod speech;
1113
use speech::speech;
14+
use unspeech_shared::AppError;
1215

1316
#[tokio::main]
14-
async fn main() {
17+
async fn main() -> Result<(), AppError> {
1518
tracing_subscriber::fmt::init();
1619

17-
let client = Client::new();
20+
let client = Client::builder()
21+
.timeout(Duration::from_secs(60))
22+
.build()?;
1823

1924
let app = Router::new()
2025
.route("/", get(root))
2126
.route("/v1/audio/speech", post(speech))
2227
.with_state(client);
2328

2429
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
25-
.await
26-
.unwrap();
30+
.await?;
2731

28-
axum::serve(listener, app)
29-
.with_graceful_shutdown(shutdown_signal())
30-
.await
31-
.unwrap();
32+
Ok(
33+
axum::serve(listener, app)
34+
.with_graceful_shutdown(shutdown_signal())
35+
.await?
36+
)
3237
}
3338

3439
async fn root() -> &'static str {

0 commit comments

Comments
 (0)