based/src/request/mod.rs
2024-12-17 23:28:43 +01:00

27 lines
551 B
Rust

use std::str::FromStr;
use rocket::response::status::BadRequest;
use serde_json::json;
pub mod context;
pub mod assets;
pub mod cache;
pub mod api;
pub fn to_uuid(id: &str) -> Result<uuid::Uuid, ApiError> {
uuid::Uuid::from_str(id).map_err(|_| no_uuid_error())
}
type ApiError = BadRequest<serde_json::Value>;
type FallibleApiResponse = Result<serde_json::Value, ApiError>;
pub fn no_uuid_error() -> ApiError {
api_error("No valid UUID")
}
pub fn api_error(msg: &str) -> ApiError {
BadRequest(json!({
"error": msg
}))
}