Refactor error handling

This commit is contained in:
Jon Staab
2026-05-15 10:32:23 -07:00
parent 5590b14074
commit 1c3e0d619a
9 changed files with 256 additions and 443 deletions
+7 -11
View File
@@ -1,21 +1,17 @@
use std::sync::Arc;
use axum::{
extract::{Path, State},
http::StatusCode,
response::Response,
};
use axum::extract::{Path, State};
use crate::api::Api;
use crate::web::{err, ok};
use crate::web::{ApiResult, not_found, ok};
pub async fn list_plans(State(api): State<Arc<Api>>) -> Response {
ok(StatusCode::OK, api.query.list_plans())
pub async fn list_plans(State(api): State<Arc<Api>>) -> ApiResult {
ok(api.query.list_plans())
}
pub async fn get_plan(State(api): State<Arc<Api>>, Path(id): Path<String>) -> Response {
pub async fn get_plan(State(api): State<Arc<Api>>, Path(id): Path<String>) -> ApiResult {
match api.query.get_plan(&id) {
Some(plan) => ok(StatusCode::OK, plan),
None => err(StatusCode::NOT_FOUND, "not-found", "plan not found"),
Some(plan) => ok(plan),
None => Err(not_found("plan not found")),
}
}