Skip to content

Commit

Permalink
feat: specified profile error reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Jun 27, 2024
1 parent 99cdf1e commit 5ce07e9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion azalea-auth/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ pub async fn check_ownership(

#[derive(Debug, Error)]
pub enum GetProfileError {
#[error("The minecraft access token is not valid. It might be expired.")]
TokenNotValid,
#[error("The microsoft account doesn't have a Minecraft profile attached to it. Either the account doesn't own the game, or it has never logged in to 'minecraft.net' to create a profile.")]
NoMinecraftProfile,
#[error("Http error: {0}")]
Http(#[from] reqwest::Error),
}
Expand All @@ -611,7 +615,14 @@ pub async fn get_profile(
.header("Authorization", format!("Bearer {minecraft_access_token}"))
.send()
.await?
.error_for_status()?
.error_for_status()
.map_err(|err| {
match err.status() {
Some(reqwest::StatusCode::UNAUTHORIZED) => GetProfileError::TokenNotValid,
Some(reqwest::StatusCode::FORBIDDEN) => GetProfileError::NoMinecraftProfile,
_ => GetProfileError::Http(err),
}
})?
.json::<ProfileResponse>()
.await?;
tracing::trace!("{:?}", res);
Expand Down

0 comments on commit 5ce07e9

Please sign in to comment.