improve error handling on play command
All checks were successful
tests / fmt (push) Successful in 1m56s
tests / test (push) Successful in 2m51s
tests / clippy (push) Successful in 2m39s
tests / build (push) Successful in 3m25s
tests / pre-commit (push) Successful in 3m55s
deploy / release-image (push) Successful in 8m5s
All checks were successful
tests / fmt (push) Successful in 1m56s
tests / test (push) Successful in 2m51s
tests / clippy (push) Successful in 2m39s
tests / build (push) Successful in 3m25s
tests / pre-commit (push) Successful in 3m55s
deploy / release-image (push) Successful in 8m5s
This commit is contained in:
@@ -238,6 +238,31 @@ pub(crate) async fn play(
|
|||||||
interaction: Box<InteractionCreate>,
|
interaction: Box<InteractionCreate>,
|
||||||
state: State,
|
state: State,
|
||||||
query: String,
|
query: String,
|
||||||
|
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||||
|
match play_inner(&interaction, Arc::clone(&state), query).await {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(e) => {
|
||||||
|
tracing::debug!("Search did not result in any tracks: {}", e);
|
||||||
|
let content = "Search did not result in any tracks.".to_string();
|
||||||
|
let embeds = vec![EmbedBuilder::new()
|
||||||
|
.description(content)
|
||||||
|
.color(colors::RED)
|
||||||
|
.build()];
|
||||||
|
state
|
||||||
|
.http
|
||||||
|
.interaction(interaction.application_id)
|
||||||
|
.update_response(&interaction.token)
|
||||||
|
.embeds(Some(&embeds))?
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn play_inner(
|
||||||
|
interaction: &InteractionCreate,
|
||||||
|
state: State,
|
||||||
|
query: String,
|
||||||
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||||
debug!(
|
debug!(
|
||||||
"play command in channel {:?} by {:?}",
|
"play command in channel {:?} by {:?}",
|
||||||
@@ -282,23 +307,7 @@ pub(crate) async fn play(
|
|||||||
|
|
||||||
debug!("query: {:?}", query);
|
debug!("query: {:?}", query);
|
||||||
|
|
||||||
let tracks = match get_tracks(query).await {
|
let tracks = get_tracks(query).await?;
|
||||||
Err(e) => {
|
|
||||||
let content = format!("{}", e);
|
|
||||||
let embeds = vec![EmbedBuilder::new()
|
|
||||||
.description(content)
|
|
||||||
.color(colors::RED)
|
|
||||||
.build()];
|
|
||||||
state
|
|
||||||
.http
|
|
||||||
.interaction(interaction.application_id)
|
|
||||||
.update_response(&interaction.token)
|
|
||||||
.embeds(Some(&embeds))?
|
|
||||||
.await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
Ok(tracks) => tracks,
|
|
||||||
};
|
|
||||||
|
|
||||||
if tracks.len() > 1 {
|
if tracks.len() > 1 {
|
||||||
let first_track = tracks.first().unwrap();
|
let first_track = tracks.first().unwrap();
|
||||||
@@ -347,7 +356,7 @@ pub(crate) async fn play(
|
|||||||
if let Ok(metadata) = src.aux_metadata().await {
|
if let Ok(metadata) = src.aux_metadata().await {
|
||||||
debug!("metadata: {:?}", metadata);
|
debug!("metadata: {:?}", metadata);
|
||||||
|
|
||||||
persistence(&interaction, yttrack, Arc::clone(&state))
|
persistence(interaction, yttrack, Arc::clone(&state))
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
tracing::error!("could not persist track: {:?}", e);
|
tracing::error!("could not persist track: {:?}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user