salvo-error-handling
Installation
SKILL.md
Salvo Error Handling
StatusError
Return a StatusError from any handler that is Result<T, StatusError>:
use salvo::prelude::*;
#[handler]
async fn get_user(req: &mut Request) -> Result<Json<User>, StatusError> {
let id = req.param::<i64>("id")
.ok_or_else(|| StatusError::bad_request().brief("Missing user ID"))?;
find_user(id).await
.ok_or_else(|| StatusError::not_found().brief("User not found"))
.map(Json)
}