Skip to content

Commit

Permalink
fix(votes): handle potential None result on total_votes
Browse files Browse the repository at this point in the history
Ensure total_votes defaults to 0 if no votes are found. This change 
prevents potential runtime errors when accessing the total votes 
and improves the reliability of the votes endpoint in the bot 
controller.
  • Loading branch information
chikof committed Nov 27, 2024
1 parent fa4323b commit 90ce008
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/controllers/bot/votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ pub async fn votes(app: AppState, Path(bot_id): Path<String>) -> AppResult<Json<
let total_votes: i64 = BotVote::belonging_to(&bot)
.select(sum_votes)
.get_result(&mut conn)
.await?;
.await
.unwrap_or(0);

Ok(Json(json!({
"bot_votes": votes,
Expand Down

0 comments on commit 90ce008

Please sign in to comment.