pub type ApiResult<T> = Result<T, ApiError>;Expand description
Result for JSON handlers: errors become ApiError JSON responses.
§Examples
use axum::extract::{Path, State};
use ocre::{ApiResult, Ctx, Json, OptionExt, params};
async fn show(State(ctx): State<Ctx>, Path(id): Path<i64>) -> ApiResult<Json<serde_json::Value>> {
let post = ctx.db()?.first("SELECT * FROM posts WHERE id = ?1", params![id]).await?.or_404()?;
Ok(Json(post))
}Aliased Type§
pub enum ApiResult<T> {
Ok(T),
Err(ApiError),
}