From 3aa708a07024766b743c81097a0228c2ac1d263c Mon Sep 17 00:00:00 2001 From: DaXcess Date: Fri, 25 Nov 2022 15:50:27 +0100 Subject: [PATCH] Made token revocation errors more obvious --- src/bot/commands/music/join.rs | 24 ++++++++++++++++++++++++ src/session/manager.rs | 3 +++ src/session/mod.rs | 2 ++ 3 files changed, 29 insertions(+) diff --git a/src/bot/commands/music/join.rs b/src/bot/commands/music/join.rs index 5605c4a..55ddfbb 100644 --- a/src/bot/commands/music/join.rs +++ b/src/bot/commands/music/join.rs @@ -242,6 +242,18 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu ) .await; + return; + } else if let SessionCreateError::NoLongerSpotifyError = why { + update_message( + &ctx, + &command, + EmbedBuilder::new() + .title("Cannot join voice channel") + .description("Spoticord no longer has access to your Spotify account. Use or go to [the accounts website](https://account.spoticord.com/) to relink your Spotify account.") + .status(Status::Error) + .build(), + ).await; + return; } @@ -284,6 +296,18 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu ) .await; + return; + } else if let SessionCreateError::NoLongerSpotifyError = why { + update_message( + &ctx, + &command, + EmbedBuilder::new() + .title("Cannot join voice channel") + .description("Spoticord no longer has access to your Spotify account. Use or go to [the accounts website](https://account.spoticord.com/) to relink your Spotify account.") + .status(Status::Error) + .build(), + ).await; + return; } diff --git a/src/session/manager.rs b/src/session/manager.rs index 41ce67e..b574f37 100644 --- a/src/session/manager.rs +++ b/src/session/manager.rs @@ -16,6 +16,9 @@ pub enum SessionCreateError { #[error("The user has not linked their Spotify account")] NoSpotifyError, + #[error("The application no longer has access to the user's Spotify account")] + NoLongerSpotifyError, + #[error("An error has occured while communicating with the database")] DatabaseError, diff --git a/src/session/mod.rs b/src/session/mod.rs index 119f07a..23978ee 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -153,6 +153,8 @@ impl SpoticordSession { if let DatabaseError::InvalidStatusCode(code) = why { if code == 404 { return Err(SessionCreateError::NoSpotifyError); + } else if code == 400 { + return Err(SessionCreateError::NoLongerSpotifyError); } }