Skip to main content

Module error

Module error 

Source
Expand description

错误处理模块

§错误处理模块

提供统一的错误类型 AppError,用于在 Axum 应用中处理各种错误

§主要特性

  • 包装 anyhow::Error,提供灵活的错误处理
  • 自动实现 IntoResponse,可直接在路由处理器中返回
  • 支持 ? 操作符,自动转换标准错误类型
  • 统一的错误响应格式 (HTTP 500)

§示例

use axum_bootstrap::error::AppError;
use axum::response::IntoResponse;

async fn handler() -> Result<impl IntoResponse, AppError> {
    // 可以直接使用 ? 操作符
    let _result = std::fs::read_to_string("file.txt")?;
    Ok("success")
}

Structs§

AppError
应用程序错误类型