Skip to content

Commit

Permalink
Return 404 when /api/songs/{id} can't find song
Browse files Browse the repository at this point in the history
  • Loading branch information
RubberDuckShobe committed Nov 6, 2024
1 parent 4739454 commit c41a694
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/api/players.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::{
};

pub fn routes() -> OpenApiRouter<AppState> {
//hack because it'll panic otherwise, see https://github.com/juhaku/utoipa/issues/1183
OpenApiRouter::new()
.routes(routes!(get_player))
.routes(routes!(get_self))
Expand Down
7 changes: 6 additions & 1 deletion src/api/songs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ async fn get_song(

let mut conn = state.db.get().await?;

let song: Song = songs::table.find(id).first(&mut conn).await?;
let song: Song = songs::table
.find(id)
.first(&mut conn)
.await
.optional()?
.ok_or_else(RouteError::new_not_found)?;
if query.with_extra_info {
let extra_info: Option<ExtraSongInfo> = ExtraSongInfo::belonging_to(&song)
.first(&mut conn)
Expand Down

0 comments on commit c41a694

Please sign in to comment.