Improve error handling

This commit is contained in:
Ilya Bizyaev 2024-07-14 19:48:26 +02:00
parent 8ad1bd1928
commit 7d5253a3f1
No known key found for this signature in database
GPG key ID: 29AACC9F9F66C5B4

View file

@ -47,12 +47,18 @@ where
<R as Requester>::DeleteWebhook: Send,
{
let Options { address, .. } = options;
let tcp_listener = tokio::net::TcpListener::bind(address).await.unwrap();
let (mut update_listener, stop_flag, app) = axum_to_router(bot, options).await?;
let stop_token = update_listener.stop_token();
tokio::spawn(async move {
let tcp_listener = tokio::net::TcpListener::bind(address)
.await
.map_err(|err| {
stop_token.stop();
err
})
.expect("Couldn't bind to the address");
axum::serve(tcp_listener, app)
.with_graceful_shutdown(stop_flag)
.await