Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit b672dff

Browse files
committed
error handling for latest github release stuff
1 parent 14acee0 commit b672dff

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/routes/latest.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use super::State;
22
use utoipa_axum::{router::OpenApiRouter, routes};
33

44
mod get {
5-
use crate::routes::GetState;
5+
use crate::routes::{ApiError, GetState};
6+
use axum::http::StatusCode;
67
use serde::Serialize;
78
use utoipa::ToSchema;
89

@@ -13,17 +14,31 @@ mod get {
1314
}
1415

1516
#[utoipa::path(get, path = "/", responses(
16-
(status = OK, body = inline(Response))
17+
(status = OK, body = inline(Response)),
18+
(status = NOT_FOUND, body = inline(ApiError)),
1719
))]
18-
pub async fn route(state: GetState) -> axum::Json<serde_json::Value> {
20+
pub async fn route(state: GetState) -> (StatusCode, axum::Json<serde_json::Value>) {
1921
let releases = state.github_releases.read().await;
2022

21-
axum::Json(
22-
serde_json::to_value(Response {
23-
name: releases.first().unwrap(),
24-
history: &releases[1..],
25-
})
26-
.unwrap(),
23+
if releases.is_empty() {
24+
return (
25+
StatusCode::NOT_FOUND,
26+
axum::Json(
27+
serde_json::to_value(ApiError::new(&["no releases found (please retry)"]))
28+
.unwrap(),
29+
),
30+
);
31+
}
32+
33+
(
34+
StatusCode::OK,
35+
axum::Json(
36+
serde_json::to_value(Response {
37+
name: releases.first().unwrap(),
38+
history: &releases[1..],
39+
})
40+
.unwrap(),
41+
),
2742
)
2843
}
2944
}

0 commit comments

Comments
 (0)